ui: minimize and maximize buttons for QtCodeFile

This change switches the code view UI to use minimize and maximize buttons within the QtCodeView instead of creating
separate windows for each maximized code file. Real icons for the buttons are still missing.
This commit is contained in:
Eberhard Graether
2015-05-19 16:27:42 +02:00
parent 1f3be0e60d
commit 5868fe4d39
14 changed files with 223 additions and 77 deletions
+113 -5
View File
@@ -3,8 +3,10 @@
#include <QPushButton>
#include <QVBoxLayout>
#include "utility/messaging/type/MessageActivateFile.h"
#include "utility/messaging/type/MessageShowFile.h"
#include "data/location/TokenLocationFile.h"
#include "qt/element/QtCodeFileList.h"
#include "qt/element/QtCodeSnippet.h"
@@ -21,6 +23,12 @@ QtCodeFile::QtCodeFile(const FilePath& filePath, QtCodeFileList* parent)
layout->setAlignment(Qt::AlignTop);
setLayout(layout);
QHBoxLayout* titleLayout = new QHBoxLayout();
titleLayout->setMargin(0);
titleLayout->setSpacing(0);
titleLayout->setAlignment(Qt::AlignLeft);
layout->addLayout(titleLayout);
m_title = new QPushButton(filePath.fileName().c_str(), this);
m_title->setObjectName("title_label");
m_title->minimumSizeHint(); // force font loading
@@ -28,9 +36,33 @@ QtCodeFile::QtCodeFile(const FilePath& filePath, QtCodeFileList* parent)
m_title->setToolTip(QString::fromStdString(filePath.str()));
m_title->setFixedWidth(m_title->fontMetrics().width(filePath.fileName().c_str()) + 32);
m_title->setSizePolicy(sizePolicy().horizontalPolicy(), QSizePolicy::Fixed);
layout->addWidget(m_title);
titleLayout->addWidget(m_title);
titleLayout->addStretch(3);
m_minimizeButton = new QPushButton(this);
m_minimizeButton->setObjectName("maximize_button");
m_minimizeButton->setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac
titleLayout->addWidget(m_minimizeButton);
m_snippetButton = new QPushButton(this);
m_snippetButton->setObjectName("maximize_button");
m_snippetButton->setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac
titleLayout->addWidget(m_snippetButton);
m_maximizeButton = new QPushButton(this);
m_maximizeButton->setObjectName("maximize_button");
m_maximizeButton->setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac
titleLayout->addWidget(m_maximizeButton);
m_minimizeButton->setEnabled(false);
m_snippetButton->setEnabled(false);
m_maximizeButton->setEnabled(false);
connect(m_title, SIGNAL(clicked()), this, SLOT(clickedTitle()));
connect(m_minimizeButton, SIGNAL(clicked()), this, SLOT(clickedMinimizeButton()));
connect(m_snippetButton, SIGNAL(clicked()), this, SLOT(clickedSnippetButton()));
connect(m_maximizeButton, SIGNAL(clicked()), this, SLOT(clickedMaximizeButton()));
update();
}
@@ -73,14 +105,22 @@ void QtCodeFile::addCodeSnippet(
std::shared_ptr<QtCodeSnippet> snippet(
new QtCodeSnippet(startLineNumber, title, code, locationFile, this));
layout()->addWidget(snippet.get());
if (locationFile->isWholeCopy)
{
m_fileSnippet = snippet;
clickedMaximizeButton();
return;
}
m_snippets.push_back(snippet);
if (m_parent->getShowMaximizeButton())
{
snippet->addMaximizeButton();
}
layout()->addWidget(snippet.get());
m_snippets.push_back(snippet);
int maxDigits = 1;
for (std::shared_ptr<QtCodeSnippet> snippet : m_snippets)
{
@@ -91,6 +131,8 @@ void QtCodeFile::addCodeSnippet(
{
snippet->updateLineNumberAreaWidthForDigits(maxDigits);
}
clickedSnippetButton();
}
void QtCodeFile::updateContent()
@@ -100,10 +142,76 @@ void QtCodeFile::updateContent()
snippet->updateContent();
}
if (m_fileSnippet)
{
m_fileSnippet->updateContent();
}
m_title->setEnabled(m_parent->getShowMaximizeButton());
}
void QtCodeFile::clickedTitle()
{
MessageShowFile(m_filePath.absoluteStr(), 0, 0).dispatch();
MessageActivateFile(m_filePath).dispatch();
}
void QtCodeFile::clickedMinimizeButton()
{
for (std::shared_ptr<QtCodeSnippet> snippet : m_snippets)
{
snippet->hide();
}
if (m_fileSnippet)
{
m_fileSnippet->hide();
}
m_minimizeButton->setEnabled(false);
if (m_snippets.size())
{
m_snippetButton->setEnabled(true);
}
m_maximizeButton->setEnabled(true);
}
void QtCodeFile::clickedSnippetButton()
{
for (std::shared_ptr<QtCodeSnippet> snippet : m_snippets)
{
snippet->show();
}
if (m_fileSnippet)
{
m_fileSnippet->hide();
}
m_minimizeButton->setEnabled(true);
m_snippetButton->setEnabled(false);
m_maximizeButton->setEnabled(true);
}
void QtCodeFile::clickedMaximizeButton()
{
for (std::shared_ptr<QtCodeSnippet> snippet : m_snippets)
{
snippet->hide();
}
if (m_fileSnippet)
{
m_fileSnippet->show();
}
else
{
MessageShowFile(m_filePath.absoluteStr(), 0, 0).dispatch();
}
m_minimizeButton->setEnabled(true);
if (m_snippets.size())
{
m_snippetButton->setEnabled(true);
}
m_maximizeButton->setEnabled(false);
}
+8
View File
@@ -41,13 +41,21 @@ public:
private slots:
void clickedTitle();
void clickedMinimizeButton();
void clickedSnippetButton();
void clickedMaximizeButton();
private:
QtCodeFileList* m_parent;
QPushButton* m_title;
QPushButton* m_minimizeButton;
QPushButton* m_snippetButton;
QPushButton* m_maximizeButton;
std::vector<std::shared_ptr<QtCodeSnippet>> m_snippets;
std::shared_ptr<QtCodeSnippet> m_fileSnippet;
const FilePath m_filePath;
};
+1 -50
View File
@@ -1,7 +1,5 @@
#include "qt/view/QtCodeView.h"
#include <QScrollBar>
#include "qt/element/QtCodeFileList.h"
#include "qt/view/QtViewWidgetWrapper.h"
#include "utility/file/FileSystem.h"
@@ -60,32 +58,12 @@ void QtCodeView::showCodeFile(const CodeSnippetParams& params)
void QtCodeView::doRefreshView()
{
setStyleSheet(m_widget);
clearClosedWindows();
for (std::shared_ptr<QtCodeFileList> window: m_windows)
{
setStyleSheet(window.get());
}
}
void QtCodeView::doShowCodeSnippets(const std::vector<CodeSnippetParams>& snippets)
{
m_widget->clearCodeSnippets();
clearClosedWindows();
for (std::shared_ptr<QtCodeFileList> window: m_windows)
{
if (m_errorMessages.size())
{
window->close();
}
else
{
window->setActiveTokenIds(m_activeTokenIds);
window->setErrorMessages(m_errorMessages);
}
}
m_widget->setActiveTokenIds(m_activeTokenIds);
m_widget->setErrorMessages(m_errorMessages);
m_widget->setShowMaximizeButton(m_errorMessages.size() == 0);
@@ -98,22 +76,7 @@ void QtCodeView::doShowCodeSnippets(const std::vector<CodeSnippetParams>& snippe
void QtCodeView::doShowCodeFile(const CodeSnippetParams& params)
{
std::shared_ptr<QtCodeFileList> ptr = createQtCodeFileList();
m_windows.push_back(ptr);
ptr->setShowMaximizeButton(false);
ptr->setActiveTokenIds(m_activeTokenIds);
ptr->setErrorMessages(m_errorMessages);
ptr->addCodeSnippet(1, params.title, params.code, params.locationFile);
ptr->setWindowTitle(params.locationFile->getFilePath().fileName().c_str());
ptr->show();
float percent = float(params.startLineNumber + params.endLineNumber) / float(params.lineCount) / 2;
float min = ptr->verticalScrollBar()->minimum();
float max = ptr->verticalScrollBar()->maximum();
ptr->verticalScrollBar()->setValue(min + (max - min) * percent);
m_widget->addCodeSnippet(1, params.title, params.code, params.locationFile);
}
std::shared_ptr<QtCodeFileList> QtCodeView::createQtCodeFileList() const
@@ -128,18 +91,6 @@ void QtCodeView::setStyleSheet(QWidget* widget) const
widget->setStyleSheet(TextAccess::createFromFile("data/gui/code_view/code_view.css")->getText().c_str());
}
void QtCodeView::clearClosedWindows()
{
for (size_t i = 0; i < m_windows.size(); i++)
{
if (!m_windows[i]->isVisible())
{
m_windows.erase(m_windows.begin() + i);
i--;
}
}
}
void QtCodeView::focusToken(const Id tokenId)
{
m_focusTokenFunctor(tokenId);
-2
View File
@@ -43,7 +43,6 @@ private:
std::shared_ptr<QtCodeFileList> createQtCodeFileList() const;
void setStyleSheet(QWidget* widget) const;
void clearClosedWindows();
QtThreadedFunctor<> m_refreshViewFunctor;
QtThreadedFunctor<const std::vector<CodeSnippetParams>&> m_showCodeSnippetsFunctor;
@@ -52,7 +51,6 @@ private:
QtThreadedFunctor<> m_defocusTokenFunctor;
QtCodeFileList* m_widget;
std::vector<std::shared_ptr<QtCodeFileList>> m_windows;
std::vector<Id> m_activeTokenIds;
std::vector<std::string> m_errorMessages;