ui: added universal font size setting and shortcuts for changing it

This change adds font size and font family to the ApplicationSettings to have a single point for manipulating them. The
font size can also be changed via the menu or the zoomIn and zoomOut shortcuts on all platforms.
This commit is contained in:
Eberhard Graether
2015-07-15 00:38:10 +02:00
parent 7275082284
commit fb170cbd5d
46 changed files with 368 additions and 152 deletions
@@ -26,12 +26,14 @@
</FrameworkSearchPaths>
</source>
<application>
<font_name><!-- STRING: font name --></font_name>
<font_size><!-- INTEGER: font size in pt --></font_size>
</application>
<code>
<TabWidth><!-- INTEGER: number of spaces to represent a tab in code files --></TabWidth>
<FontName><!-- STRING: name of the font used for source view --></FontName> <!-- DEPRECATED -->
<FontSize><!-- INTEGER: size of the font in the source view --></FontSize> <!-- DEPRECATED -->
<snippet>
<snap_range><!-- INTEGER: max amount of lines that the current snippet will be extended to snap to scope start/end --></snap_range>
<expand_range><!-- INTEGER: amount of lines that the snippet range (not snapped) will be extended --></expand_range>
+1 -12
View File
@@ -13,7 +13,6 @@
border-top-left-radius: 10px;
border-top-right-radius: 10px;
margin-bottom: 5px;
min-height: 28px;
padding-right: 5px;
}
@@ -21,9 +20,8 @@
background: none;
border: none;
border-radius: 3px;
font-size: 14px;
padding: 2px 4px;
margin: 2px 8px;
margin: 1px 8px 3px;
}
#code_file #title_label:hover {
@@ -48,8 +46,6 @@
background: none;
color: gray;
border: none;
font-family: "Source Code Pro";
font-size: 14px;
}
#code_file #code_snippet #dots {
@@ -63,13 +59,6 @@
#code_area {
background-color: transparent;
font-family: "Source Code Pro";
font-size: 14px;
}
#code_area #line_number_area {
font-family: "Source Code Pro";
font-size: 14px;
}
#code_file #maximize_button, #code_file #snippet_button, #code_file #minimize_button {
@@ -1,8 +0,0 @@
QPushButton {
border: none;
font-family: "Source Code Pro";
font-size: 16px;
height: 20px;
padding-left: 4px;
padding-right: 4px;
}
@@ -13,23 +13,17 @@ QWidget#search_box_container {
QLineEdit#search_box {
background: #E0E0E0;
border: none;
font-family: "Source Code Pro";
font-size: 16px;
height: 24px;
selection-background-color: #B2B2B2;
}
QWidget#search_box_highlight {
background: #B2B2B2;
border: none;
height: 24px;
}
QAbstractItemView#search_box_popup {
background-color: white;
border: none;
font-family: "Source Code Pro";
font-size: 14pt;
margin: 8px 0 0;
min-height: 26px;
selection-background-color: #B2B2B2;
@@ -41,7 +35,6 @@ QPushButton#search_button {
border-bottom-right-radius: 12px;
border-top-right-radius: 12px;
background-position: 15px 5px;
height: 30px;
width: 30px;
}
@@ -53,18 +46,6 @@ QPushButton#search_button {
background: #626262;
}
/*QPushButton#case_sensitive_button {
border: none;
border-image: url(data/gui/search_view/images/button_case_sensitive_inactive.png);
height: 26px;
width: 26px;
margin-left: 4px;
}
QPushButton#case_sensitive_button:checked {
border-image: url(data/gui/search_view/images/button_case_sensitive_active.png);
}*/
QToolTip {
background-color: rgb(204, 204, 204);
border: 1px solid rgb(0, 0, 0);
+1 -1
View File
@@ -145,7 +145,7 @@ void QtAutocompletionDelegate::paint(QPainter* painter, const QStyleOptionViewIt
if (font.pointSize() > 0)
{
QFont typeFont = font;
typeFont.setPointSize(10);
typeFont.setPointSize(ApplicationSettings::getInstance()->getFontSize() - 4);
painter->setFont(typeFont);
}
+12 -6
View File
@@ -57,9 +57,8 @@ QtCodeArea::QtCodeArea(
setObjectName("code_area");
setReadOnly(true);
setFrameStyle(QFrame::NoFrame);
setSizePolicy(sizePolicy().horizontalPolicy(), QSizePolicy::Fixed);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setLineWrapMode(QPlainTextEdit::NoWrap);
setSizePolicy(sizePolicy().horizontalPolicy(), QSizePolicy::Fixed);
m_lineNumberArea = new LineNumberArea(this);
m_highlighter = new QtHighlighter(document());
@@ -90,9 +89,16 @@ QtCodeArea::~QtCodeArea()
QSize QtCodeArea::sizeHint() const
{
int width = 480;
int height = (document()->size().height() + 0.7f) * fontMetrics().lineSpacing() - 3;
return QSize(width, height);
QTextBlock block = firstVisibleBlock();
float height = blockBoundingGeometry(block).translated(contentOffset()).top();
while (block.isValid())
{
height += blockBoundingRect(block).height();
block = block.next();
}
return QSize(320, height + 1);
}
void QtCodeArea::lineNumberAreaPaintEvent(QPaintEvent *event)
@@ -170,7 +176,7 @@ void QtCodeArea::showEvent(QShowEvent* event)
int tabWidth = ApplicationSettings::getInstance()->getCodeTabWidth();
setTabStopWidth(tabWidth * fontMetrics().width('9'));
setMaximumHeight(sizeHint().height());
setFixedHeight(sizeHint().height());
}
void QtCodeArea::paintEvent(QPaintEvent* event)
+1 -1
View File
@@ -49,7 +49,7 @@ public:
);
virtual ~QtCodeArea();
QSize sizeHint() const;
virtual QSize sizeHint() const;
void lineNumberAreaPaintEvent(QPaintEvent *event);
int lineNumberDigits() const;
+3
View File
@@ -39,9 +39,12 @@ QtCodeFile::QtCodeFile(const FilePath& filePath, QtCodeFileList* parent)
m_title->setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac
m_title->setToolTip(QString::fromStdString(filePath.str()));
m_title->setFixedWidth(m_title->fontMetrics().width(filePath.fileName().c_str()) + 32);
m_title->setFixedHeight(std::max(m_title->fontMetrics().height() * 1.2, 28.0));
m_title->setSizePolicy(sizePolicy().horizontalPolicy(), QSizePolicy::Fixed);
titleLayout->addWidget(m_title);
titleWidget->setMinimumHeight(m_title->height() + 4);
titleLayout->addStretch(3);
m_minimizeButton = new QPushButton(this);
+23 -2
View File
@@ -21,6 +21,7 @@
#include "utility/messaging/type/MessageSaveProject.h"
#include "utility/messaging/type/MessageUndo.h"
#include "utility/messaging/type/MessageWindowFocus.h"
#include "utility/messaging/type/MessageZoom.h"
QtMainWindow::QtMainWindow()
{
@@ -34,6 +35,7 @@ QtMainWindow::QtMainWindow()
setupProjectMenu();
setupEditMenu();
setupViewMenu();
setupHelpMenu();
setupShortcuts();
@@ -216,6 +218,16 @@ void QtMainWindow::redo()
MessageRedo().dispatch();
}
void QtMainWindow::zoomIn()
{
MessageZoom(true).dispatch();
}
void QtMainWindow::zoomOut()
{
MessageZoom(false).dispatch();
}
void QtMainWindow::handleEscapeShortcut()
{
m_startScreen->hide();
@@ -247,11 +259,20 @@ void QtMainWindow::setupEditMenu()
menuBar()->addMenu(menu);
menu->addAction(tr("&Refresh"), this, SLOT(refresh()), QKeySequence::Refresh);
menu->addAction(tr("Undo"), this, SLOT(undo()), QKeySequence::Undo );
menu->addAction(tr("Redo"), this, SLOT(redo()), QKeySequence::Redo );
menu->addAction(tr("Undo"), this, SLOT(undo()), QKeySequence::Undo);
menu->addAction(tr("Redo"), this, SLOT(redo()), QKeySequence::Redo);
menu->addAction(tr("&Find"), this, SLOT(find()), QKeySequence::Find);
}
void QtMainWindow::setupViewMenu()
{
QMenu *menu = new QMenu(tr("&View"), this);
menuBar()->addMenu(menu);
menu->addAction(tr("Larger font"), this, SLOT(zoomIn()), QKeySequence::ZoomIn);
menu->addAction(tr("Smaller font"), this, SLOT(zoomOut()), QKeySequence::ZoomOut);
}
void QtMainWindow::setupHelpMenu()
{
QMenu *menu = new QMenu(tr("&Help"), this);
+3
View File
@@ -45,12 +45,15 @@ public slots:
void showLicences();
void undo();
void redo();
void zoomIn();
void zoomOut();
void handleEscapeShortcut();
private:
void setupEditMenu();
void setupProjectMenu();
void setupViewMenu();
void setupHelpMenu();
void setupShortcuts();
+10
View File
@@ -6,6 +6,8 @@
#include "utility/messaging/type/MessageAutoRefreshChanged.h"
#include "utility/messaging/type/MessageRefresh.h"
#include "settings/ApplicationSettings.h"
QtRefreshBar::QtRefreshBar()
{
setObjectName("refresh_bar");
@@ -48,3 +50,11 @@ void QtRefreshBar::autoRefreshClicked()
{
MessageAutoRefreshChanged(m_autoRefreshButton->isChecked()).dispatch();
}
void QtRefreshBar::refreshStyle()
{
float height = std::max(ApplicationSettings::getInstance()->getFontSize() + 16, 30);
m_refreshButton->setFixedHeight(height);
m_autoRefreshButton->setFixedHeight(height);
}
+2
View File
@@ -14,6 +14,8 @@ public:
QtRefreshBar();
virtual ~QtRefreshBar();
void refreshStyle();
private slots:
void refreshClicked();
void autoRefreshClicked();
+10 -8
View File
@@ -5,6 +5,7 @@
#include <QPushButton>
#include "qt/element/QtSmartSearchBox.h"
#include "settings/ApplicationSettings.h"
QtSearchBar::QtSearchBar()
{
@@ -23,7 +24,7 @@ QtSearchBar::QtSearchBar()
layout->addWidget(m_searchBoxContainer);
QBoxLayout* innerLayout = new QHBoxLayout();
innerLayout->setContentsMargins(7, 3, 5, 3);
innerLayout->setContentsMargins(7, 3, 5, 2);
m_searchBoxContainer->setLayout(innerLayout);
m_searchBox = new QtSmartSearchBox(m_searchBoxContainer);
@@ -41,14 +42,9 @@ QtSearchBar::QtSearchBar()
m_searchButton->setIcon(QIcon("data/gui/search_view/images/search.png"));
layout->addWidget(m_searchButton);
// m_caseSensitiveButton = new QPushButton(this);
// m_caseSensitiveButton->setObjectName("case_sensitive_button");
// m_caseSensitiveButton->setCheckable(true);
// m_caseSensitiveButton->setToolTip("case sensitive");
// m_caseSensitiveButton->setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac
// layout->addWidget(m_caseSensitiveButton);
connect(m_searchButton, SIGNAL(clicked()), m_searchBox, SLOT(search()));
refreshStyle();
}
QtSearchBar::~QtSearchBar()
@@ -83,3 +79,9 @@ QAbstractItemView* QtSearchBar::getCompleterPopup()
}
return nullptr;
}
void QtSearchBar::refreshStyle()
{
m_searchBox->setFixedHeight(std::max(ApplicationSettings::getInstance()->getFontSize() + 11, 25));
m_searchButton->setFixedHeight(m_searchBox->height() + 5);
}
+2 -1
View File
@@ -28,11 +28,12 @@ public:
QAbstractItemView* getCompleterPopup();
void refreshStyle();
private:
QWidget* m_searchBoxContainer; // used for correct clipping inside the search box
QtSmartSearchBox* m_searchBox;
QPushButton* m_searchButton;
// QPushButton* m_caseSensitiveButton;
};
#endif // QT_SEARCH_BAR_H
+9 -9
View File
@@ -581,10 +581,11 @@ void QtSmartSearchBox::updateElements()
std::shared_ptr<QtQueryElement> element = std::make_shared<QtQueryElement>(QString::fromStdString(name), this);
m_elements.push_back(element);
std::string color = "#000000";
std::string hoverColor = "#000000";
if(token.queryNodeType == QueryNode::QUERYNODETYPE_TOKEN)
if (token.queryNodeType == QueryNode::QUERYNODETYPE_TOKEN)
{
element->setObjectName(QString::fromStdString("search_element_" + token.getNodeTypeAsString()));
color = ApplicationSettings::getInstance()->getNodeTypeColor(token.nodeType);
@@ -597,19 +598,18 @@ void QtSmartSearchBox::updateElements()
hoverColor = ApplicationSettings::getInstance()->getQueryNodeTypeColor(token.queryNodeType, "hover");
}
std::string stylesheet = "QPushButton {background-color:";
stylesheet += color;
stylesheet += ";} QPushButton:hover{ background-color:";
stylesheet += hoverColor;
stylesheet += ";}";
std::stringstream css;
css << "QPushButton { border: none; padding: 0px 4px; background-color:";
css << color;
css << ";} QPushButton:hover { background-color:";
css << hoverColor;
css << ";}";
element->setStyleSheet(stylesheet.c_str());
element->setStyleSheet(css.str().c_str());
connect(element.get(), SIGNAL(wasChecked(QtQueryElement*)), this, SLOT(onElementSelected(QtQueryElement*)));
}
setStyleSheet(TextAccess::createFromFile("data/gui/search_view/search_element.css")->getText().c_str());
updatePlaceholder();
hideAutoCompletions();
+13 -2
View File
@@ -3,9 +3,10 @@
#include <QPushButton>
#include <QHBoxLayout>
#include <utility/messaging/type/MessageUndo.h>
#include <utility/messaging/type/MessageRedo.h>
#include "utility/messaging/type/MessageUndo.h"
#include "utility/messaging/type/MessageRedo.h"
#include "settings/ApplicationSettings.h"
QtUndoRedo::QtUndoRedo()
{
@@ -35,6 +36,8 @@ QtUndoRedo::QtUndoRedo()
connect(m_undoButton, SIGNAL(clicked()), this, SLOT(undo()));
connect(m_redoButton, SIGNAL(clicked()), this, SLOT(redo()));
refreshStyle();
}
QtUndoRedo::~QtUndoRedo()
@@ -60,3 +63,11 @@ void QtUndoRedo::setRedoButtonEnabled(bool enabled)
{
m_redoButton->setEnabled(enabled);
}
void QtUndoRedo::refreshStyle()
{
float height = std::max(ApplicationSettings::getInstance()->getFontSize() + 16, 30);
m_undoButton->setFixedHeight(height);
m_redoButton->setFixedHeight(height);
}
+3
View File
@@ -15,9 +15,12 @@ class QtUndoRedo
public:
QtUndoRedo();
~QtUndoRedo();
void setRedoButtonEnabled(bool enabled);
void setUndoButtonEnabled(bool enabled);
void refreshStyle();
private slots:
void undo();
void redo();
+6 -4
View File
@@ -15,7 +15,7 @@ QtStraightLineItem::QtStraightLineItem(QGraphicsItem* parent)
this->setAcceptHoverEvents(true);
m_circle = new QtRoundedRectItem(this);
m_circle->setRadius(10);
m_circle->setRadius(100);
m_circle->setBrush(QBrush(QColor("#FFF")));
m_circle->setAcceptHoverEvents(true);
@@ -87,13 +87,15 @@ void QtStraightLineItem::updateLine(
Vec2f mid = (op + tp) / 2;
size_t radius = GraphViewStyle::getFontSizeOfExpandToggleNode();
if (showArrow)
{
Vec2f unit = (tp - op).normalize();
Vec2f nUnit(-unit.y, unit.x);
Vec2f arrow = mid + unit * 22;
Vec2f arrow = mid + unit * (radius + 13);
Vec2f arrowSide = mid + unit * 15 + nUnit * 7;
Vec2f arrowSide = mid + unit * (radius + 6) + nUnit * 7;
m_arrowRight->setLine(arrow.x, arrow.y, arrowSide.x, arrowSide.y);
arrowSide -= nUnit * 14;
@@ -111,7 +113,7 @@ void QtStraightLineItem::updateLine(
m_arrowRight->hide();
}
m_circle->setRect(mid.x - 10, mid.y - 10, 20, 20);
m_circle->setRect(mid.x - radius, mid.y - radius, 2 * radius, 2 * radius);
m_circle->setPen(QPen(QColor("#E0E0E0"), 2));
QString numberStr = QString::number(number);
+9 -1
View File
@@ -1,10 +1,13 @@
#include "qt/view/QtCodeView.h"
#include <sstream>
#include "utility/file/FileSystem.h"
#include "utility/text/TextAccess.h"
#include "qt/element/QtCodeFileList.h"
#include "qt/view/QtViewWidgetWrapper.h"
#include "settings/ApplicationSettings.h"
QtCodeView::QtCodeView(ViewLayout* viewLayout)
: CodeView(viewLayout)
@@ -114,5 +117,10 @@ void QtCodeView::doDefocusToken()
void QtCodeView::setStyleSheet(QWidget* widget) const
{
widget->setStyleSheet(TextAccess::createFromFile("data/gui/code_view/code_view.css")->getText().c_str());
std::stringstream css;
css << TextAccess::createFromFile("data/gui/code_view/code_view.css")->getText();
css << "* { font-size: " << ApplicationSettings::getInstance()->getFontSize() << "pt; }";
css << "#code_file #code_snippet * { font-family: " << ApplicationSettings::getInstance()->getFontName() << "; }";
widget->setStyleSheet(css.str().c_str());
}
+5
View File
@@ -6,3 +6,8 @@ float QtGraphViewStyleImpl::getCharWidthForNodeType(Node::NodeType type)
{
return QFontMetrics(QtGraphNode::getFontForNodeType(type)).width("QtGraphNode::QtGraphNode::QtGraphNode") / 37.0f;
}
float QtGraphViewStyleImpl::getCharHeightForNodeType(Node::NodeType type)
{
return QFontMetrics(QtGraphNode::getFontForNodeType(type)).height();
}
+1
View File
@@ -9,6 +9,7 @@ class QtGraphViewStyleImpl
{
public:
virtual float getCharWidthForNodeType(Node::NodeType type);
virtual float getCharHeightForNodeType(Node::NodeType type);
};
#endif // QT_GRAPH_VIEW_STYLE_IMPL_H
+10 -3
View File
@@ -1,8 +1,12 @@
#include "qt/view/QtRefreshView.h"
#include <sstream>
#include "utility/text/TextAccess.h"
#include "component/controller/RefreshController.h"
#include "qt/view/QtViewWidgetWrapper.h"
#include "utility/text/TextAccess.h"
#include "settings/ApplicationSettings.h"
QtRefreshView::QtRefreshView(ViewLayout* viewLayout)
: RefreshView(viewLayout)
@@ -33,11 +37,14 @@ void QtRefreshView::refreshView()
void QtRefreshView::doRefreshView()
{
setStyleSheet();
m_widget->refreshStyle();
}
void QtRefreshView::setStyleSheet()
{
std::string css = TextAccess::createFromFile("data/gui/refresh_view/refresh_view.css")->getText();
std::stringstream css;
css << TextAccess::createFromFile("data/gui/refresh_view/refresh_view.css")->getText();
css << "* { font-size: " << ApplicationSettings::getInstance()->getFontSize() << "pt; }";
m_widget->setStyleSheet(css.c_str());
m_widget->setStyleSheet(css.str().c_str());
}
+13 -4
View File
@@ -1,8 +1,12 @@
#include "qt/view/QtSearchView.h"
#include <sstream>
#include "utility/text/TextAccess.h"
#include "component/controller/SearchController.h"
#include "qt/view/QtViewWidgetWrapper.h"
#include "utility/text/TextAccess.h"
#include "settings/ApplicationSettings.h"
QtSearchView::QtSearchView(ViewLayout* viewLayout)
: SearchView(viewLayout)
@@ -51,6 +55,7 @@ void QtSearchView::setAutocompletionList(const std::vector<SearchMatch>& autocom
void QtSearchView::doRefreshView()
{
setStyleSheet();
m_widget->refreshStyle();
m_widget->setMatches(std::deque<SearchMatch>());
}
@@ -73,12 +78,16 @@ void QtSearchView::doSetAutocompletionList(const std::vector<SearchMatch>& autoc
void QtSearchView::setStyleSheet()
{
std::string css = TextAccess::createFromFile("data/gui/search_view/search_view.css")->getText();
std::stringstream css;
css << TextAccess::createFromFile("data/gui/search_view/search_view.css")->getText();
css << "* { font-size: " << ApplicationSettings::getInstance()->getFontSize() << "pt; }";
css << "#search_box, #search_box *, #search_box_popup { font-family: " << ApplicationSettings::getInstance()->getFontName() << "; }";
css << "#search_box, #search_box * { font-size: " << ApplicationSettings::getInstance()->getFontSize() + 2 << "pt; }";
m_widget->setStyleSheet(css.c_str());
m_widget->setStyleSheet(css.str().c_str());
if (m_widget->getCompleterPopup())
{
m_widget->getCompleterPopup()->setStyleSheet(css.c_str());
m_widget->getCompleterPopup()->setStyleSheet(css.str().c_str());
}
}
+11 -5
View File
@@ -1,8 +1,12 @@
#include "qt/view/QtUndoRedoView.h"
#include <sstream>
#include "utility/text/TextAccess.h"
#include "qt/view/QtMainView.h"
#include "qt/view/QtViewWidgetWrapper.h"
#include "utility/text/TextAccess.h"
#include "settings/ApplicationSettings.h"
QtUndoRedoView::QtUndoRedoView(ViewLayout* viewLayout)
: UndoRedoView(viewLayout)
@@ -28,15 +32,17 @@ void QtUndoRedoView::initView()
void QtUndoRedoView::refreshView()
{
setStyleSheet();
m_widget->refreshStyle();
}
void QtUndoRedoView::setStyleSheet()
{
std::string css = TextAccess::createFromFile("data/gui/undoredo_view/undoredo_view.css")->getText();
m_widget->setStyleSheet(css.c_str());
std::stringstream css;
css << TextAccess::createFromFile("data/gui/undoredo_view/undoredo_view.css")->getText();
css << "* { font-size: " << ApplicationSettings::getInstance()->getFontSize() << "pt; }";
m_widget->setStyleSheet(css.str().c_str());
}
void QtUndoRedoView::doSetRedoButtonEnabled(bool enabled)
@@ -52,7 +52,7 @@ void QtGraphNodeAccess::updateStyle()
font.setCapitalization(QFont::AllUppercase);
m_text->setFont(font);
m_text->setPos(style.textOffset.x + m_accessIconSize + 3, style.textOffset.y + m_accessIconSize / 2 - 1);
m_text->setPos(style.textOffset.x + m_accessIconSize + 3, style.textOffset.x + m_accessIconSize + 2 - style.fontSize);
m_accessIcon->setPos(style.textOffset.x, style.textOffset.y);
}
@@ -64,11 +64,11 @@ void QtGraphNodeExpandToggle::updateStyle()
m_text->setPos(
(m_rect->rect().width() - QFontMetrics(m_text->font()).width(m_text->text())) / 2,
5
6
);
m_icon->setPos(
(m_rect->rect().width() - m_icon->pixmap().width() / QtDeviceScaledPixmap::devicePixelRatio()) / 2,
(m_invisibleSubNodeCount == 0 ? 9 : 14)
(m_invisibleSubNodeCount == 0 ? m_rect->rect().height() / 2 - 2 : m_rect->rect().height() - 8)
);
}
+15 -1
View File
@@ -6,6 +6,7 @@
#include "utility/messaging/type/MessageStatus.h"
#include "utility/scheduling/TaskScheduler.h"
#include "component/view/GraphViewStyle.h"
#include "component/view/MainView.h"
#include "component/view/ViewFactory.h"
#include "data/StorageCache.h"
@@ -31,9 +32,11 @@ std::shared_ptr<Application> Application::create(ViewFactory* viewFactory)
void Application::loadSettings()
{
ApplicationSettings::getInstance()->load("data/ApplicationSettings.xml");
GraphViewStyle::loadStyleSettings();
}
Application::Application()
: m_isInitialParse(true)
{
TaskScheduler::getInstance()->startSchedulerLoopThreaded();
MessageQueue::getInstance()->setSendMessagesAsTasks(true);
@@ -96,11 +99,13 @@ void Application::handleMessage(MessageFinishedParsing* message)
{
m_project->logStats();
if (message->errorCount > 0)
if (!m_isInitialParse || message->errorCount > 0)
{
return;
}
m_isInitialParse = false;
Id mainId = m_storageCache->getIdForNodeWithName("main");
if (!mainId)
@@ -126,17 +131,26 @@ void Application::handleMessage(MessageFinishedParsing* message)
void Application::handleMessage(MessageLoadProject* message)
{
m_isInitialParse = true;
loadProject(message->projectSettingsFilePath);
}
void Application::handleMessage(MessageLoadSource* message)
{
m_isInitialParse = true;
loadSource(message->sourceDirectoryPath);
}
void Application::handleMessage(MessageRefresh* message)
{
loadSettings();
if (message->uiOnly)
{
m_componentManager->refreshViews();
return;
}
reloadProject();
}
+2
View File
@@ -48,6 +48,8 @@ private:
std::shared_ptr<MainView> m_mainView;
std::shared_ptr<ComponentManager> m_componentManager;
bool m_isInitialParse;
};
#endif // APPLICATION_H
+2 -1
View File
@@ -267,15 +267,16 @@ add_files(
utility/messaging/type/MessageInterruptTasks.h
utility/messaging/type/MessageLoadProject.h
utility/messaging/type/MessageLoadSource.h
utility/messaging/type/MessageRedo.h
utility/messaging/type/MessageRefresh.h
utility/messaging/type/MessageSaveProject.h
utility/messaging/type/MessageSearch.h
utility/messaging/type/MessageSearchAutocomplete.h
utility/messaging/type/MessageShowFile.h
utility/messaging/type/MessageStatus.h
utility/messaging/type/MessageRedo.h
utility/messaging/type/MessageUndo.h
utility/messaging/type/MessageWindowFocus.h
utility/messaging/type/MessageZoom.h
utility/messaging/Message.h
utility/messaging/MessageBase.h
@@ -25,7 +25,7 @@ const uint CodeController::s_lineRadius = 2;
void CodeController::handleMessage(MessageActivateTokens* message)
{
if (message->isIgnorable())
if (message->isEdge && message->isIgnorable())
{
return;
}
@@ -1,8 +1,10 @@
#include "component/controller/FeatureController.h"
#include "utility/messaging/type/MessageActivateTokens.h"
#include "utility/messaging/type/MessageRefresh.h"
#include "data/access/StorageAccess.h"
#include "settings/ApplicationSettings.h"
FeatureController::FeatureController(StorageAccess* storageAccess)
: m_storageAccess(storageAccess)
@@ -85,3 +87,12 @@ void FeatureController::handleMessage(MessageSearch* message)
m.undoRedoType = message->undoRedoType;
m.dispatchImmediately();
}
void FeatureController::handleMessage(MessageZoom* message)
{
ApplicationSettings* settings = ApplicationSettings::getInstance().get();
settings->setFontSize(std::max(settings->getFontSize() + (message->zoomIn ? 1 : -1), 5));
settings->save();
MessageRefresh(true).dispatch();
}
@@ -7,6 +7,7 @@
#include "utility/messaging/type/MessageActivateNode.h"
#include "utility/messaging/type/MessageActivateTokenLocation.h"
#include "utility/messaging/type/MessageSearch.h"
#include "utility/messaging/type/MessageZoom.h"
#include "component/controller/Controller.h"
@@ -19,6 +20,7 @@ class FeatureController
, public MessageListener<MessageActivateNode>
, public MessageListener<MessageActivateTokenLocation>
, public MessageListener<MessageSearch>
, public MessageListener<MessageZoom>
{
public:
FeatureController(StorageAccess* storageAccess);
@@ -30,6 +32,7 @@ private:
virtual void handleMessage(MessageActivateNode* message);
virtual void handleMessage(MessageActivateTokenLocation* message);
virtual void handleMessage(MessageSearch* message);
virtual void handleMessage(MessageZoom* message);
StorageAccess* m_storageAccess;
};
@@ -712,7 +712,7 @@ void GraphController::layoutNestingRecursive(DummyNode& node) const
}
subNode.position.x = margins.left + x;
subNode.position.y = margins.top + y;
subNode.position.y = margins.top + margins.charHeight + y;
if (layoutHorizontal)
{
@@ -747,7 +747,7 @@ void GraphController::layoutNestingRecursive(DummyNode& node) const
}
node.size.x = margins.left + width + margins.right;
node.size.y = margins.top + y + height + margins.bottom;
node.size.y = margins.top + margins.charHeight + y + height + margins.bottom;
for (DummyNode& subNode : node.subNodes)
{
@@ -1,5 +1,7 @@
#include "component/controller/RefreshController.h"
#include "utility/messaging/type/MessageRefresh.h"
#include "component/view/RefreshView.h"
RefreshController::RefreshController()
@@ -16,11 +18,6 @@ void RefreshController::handleMessage(MessageAutoRefreshChanged* message)
m_autoRefreshEnabled = message->enabled;
}
void RefreshController::handleMessage(MessageRefresh* message)
{
getView()->refreshView();
}
void RefreshController::handleMessage(MessageWindowFocus* message)
{
if (m_autoRefreshEnabled)
@@ -4,7 +4,6 @@
#include "component/controller/Controller.h"
#include "utility/messaging/MessageListener.h"
#include "utility/messaging/type/MessageAutoRefreshChanged.h"
#include "utility/messaging/type/MessageRefresh.h"
#include "utility/messaging/type/MessageWindowFocus.h"
class RefreshView;
@@ -12,7 +11,6 @@ class RefreshView;
class RefreshController
: public Controller
, public MessageListener<MessageAutoRefreshChanged>
, public MessageListener<MessageRefresh>
, public MessageListener<MessageWindowFocus>
{
public:
@@ -21,7 +19,6 @@ public:
private:
virtual void handleMessage(MessageAutoRefreshChanged* message);
virtual void handleMessage(MessageRefresh* message);
virtual void handleMessage(MessageWindowFocus* message);
RefreshView* getView();
@@ -99,6 +99,34 @@ void UndoRedoController::handleMessage(MessageRedo* message)
}
}
void UndoRedoController::handleMessage(MessageRefresh* message)
{
if (!m_lastCommand.message)
{
return;
}
if (m_lastCommand.order > 0)
{
replayCommands(false);
}
std::shared_ptr<MessageBase> msg = m_lastCommand.message;
if (m_undo.size())
{
m_lastCommand = m_undo.back();
m_undo.pop_back();
}
else
{
m_lastCommand.message.reset();
}
msg->undoRedoType = MessageBase::UNDOTYPE_REDO;
msg->dispatch();
}
void UndoRedoController::handleMessage(MessageSearch* message)
{
if (m_lastCommand.message && m_lastCommand.message->getType() == message->getType() &&
@@ -112,6 +140,11 @@ void UndoRedoController::handleMessage(MessageSearch* message)
}
void UndoRedoController::handleMessage(MessageUndo* message)
{
replayCommands(true);
}
void UndoRedoController::replayCommands(bool removeLast)
{
if (!m_undo.empty())
{
@@ -131,8 +164,17 @@ void UndoRedoController::handleMessage(MessageUndo* message)
}
m = m_undo.back().message;
m_undo.pop_back();
m->undoRedoType = MessageBase::UNDOTYPE_UNDO;
if (removeLast)
{
m_undo.pop_back();
m->undoRedoType = MessageBase::UNDOTYPE_UNDO;
}
else
{
m->undoRedoType = MessageBase::UNDOTYPE_IGNORE;
}
m->dispatch();
}
}
@@ -14,6 +14,7 @@
#include "utility/messaging/type/MessageLoadProject.h"
#include "utility/messaging/type/MessageLoadSource.h"
#include "utility/messaging/type/MessageRedo.h"
#include "utility/messaging/type/MessageRefresh.h"
#include "utility/messaging/type/MessageSearch.h"
#include "utility/messaging/type/MessageUndo.h"
@@ -32,6 +33,7 @@ class UndoRedoController
, public MessageListener<MessageLoadProject>
, public MessageListener<MessageLoadSource>
, public MessageListener<MessageRedo>
, public MessageListener<MessageRefresh>
, public MessageListener<MessageSearch>
, public MessageListener<MessageUndo>
{
@@ -59,9 +61,12 @@ private:
virtual void handleMessage(MessageLoadProject* message);
virtual void handleMessage(MessageLoadSource* message);
virtual void handleMessage(MessageRedo* message);
virtual void handleMessage(MessageRefresh* message);
virtual void handleMessage(MessageSearch* message);
virtual void handleMessage(MessageUndo* message);
void replayCommands(bool removeLast);
void processCommand(const Command& command);
void processNormalCommand(const Command& command);
void processRedoCommand(const Command& command);
+43 -17
View File
@@ -14,6 +14,7 @@ GraphViewStyle::NodeMargins::NodeMargins()
, spacingY(0)
, minWidth(0)
, charWidth(0.0f)
, charHeight(0.0f)
{
}
@@ -56,6 +57,15 @@ void GraphViewStyle::setImpl(std::shared_ptr<GraphViewStyleImpl> impl)
s_impl = impl;
}
void GraphViewStyle::loadStyleSettings()
{
s_fontSize = ApplicationSettings::getInstance()->getFontSize();
s_fontName = ApplicationSettings::getInstance()->getFontName();
s_charWidths.clear();
s_charHeights.clear();
}
float GraphViewStyle::getCharWidthForNodeType(Node::NodeType type)
{
std::map<Node::NodeType, float>::const_iterator it = s_charWidths.find(type);
@@ -70,13 +80,27 @@ float GraphViewStyle::getCharWidthForNodeType(Node::NodeType type)
return charWidth;
}
float GraphViewStyle::getCharHeightForNodeType(Node::NodeType type)
{
std::map<Node::NodeType, float>::const_iterator it = s_charHeights.find(type);
if (it != s_charHeights.end())
{
return it->second;
}
float charHeight = getImpl()->getCharHeightForNodeType(type);
s_charHeights.emplace(type, charHeight);
return charHeight;
}
size_t GraphViewStyle::getFontSizeForNodeType(Node::NodeType type)
{
switch (type)
{
case Node::NODE_UNDEFINED:
case Node::NODE_NAMESPACE:
return 12;
return s_fontSize - 2;
case Node::NODE_UNDEFINED_TYPE:
case Node::NODE_STRUCT:
@@ -85,7 +109,7 @@ size_t GraphViewStyle::getFontSizeForNodeType(Node::NodeType type)
case Node::NODE_TYPEDEF:
case Node::NODE_TEMPLATE_PARAMETER_TYPE:
case Node::NODE_FILE:
return 14;
return s_fontSize;
case Node::NODE_UNDEFINED_FUNCTION:
case Node::NODE_UNDEFINED_VARIABLE:
@@ -94,23 +118,23 @@ size_t GraphViewStyle::getFontSizeForNodeType(Node::NodeType type)
case Node::NODE_GLOBAL_VARIABLE:
case Node::NODE_FIELD:
case Node::NODE_ENUM_CONSTANT:
return 11;
return s_fontSize - 3;
}
}
size_t GraphViewStyle::getFontSizeOfAccessNode()
{
return 11;
return s_fontSize - 3;
}
size_t GraphViewStyle::getFontSizeOfExpandToggleNode()
{
return 9;
return s_fontSize - 5;
}
std::string GraphViewStyle::getFontNameForNodeType(Node::NodeType type)
{
return "Source Code Pro";
return s_fontName;
}
std::string GraphViewStyle::getFontNameOfAccessNode()
@@ -134,7 +158,7 @@ GraphViewStyle::NodeMargins GraphViewStyle::getMarginsForNodeType(Node::NodeType
case Node::NODE_UNDEFINED:
case Node::NODE_NAMESPACE:
margins.left = margins.right = 15;
margins.top = 28;
margins.top = 10;
margins.bottom = 15;
break;
@@ -148,33 +172,30 @@ GraphViewStyle::NodeMargins GraphViewStyle::getMarginsForNodeType(Node::NodeType
if (hasChildren)
{
margins.left = margins.right = 10;
margins.top = 33;
margins.top = 15;
margins.bottom = 10;
}
else
{
margins.left = margins.right = 8;
margins.top = margins.bottom = 17;
margins.top = margins.bottom = 8;
}
break;
case Node::NODE_UNDEFINED_FUNCTION:
case Node::NODE_FUNCTION:
case Node::NODE_METHOD:
margins.left = margins.right = 5;
margins.top = margins.bottom = 10;
break;
case Node::NODE_UNDEFINED_VARIABLE:
case Node::NODE_GLOBAL_VARIABLE:
case Node::NODE_FIELD:
case Node::NODE_ENUM_CONSTANT:
margins.left = margins.right = 5;
margins.top = margins.bottom = 10;
margins.top = margins.bottom = 3;
break;
}
margins.charWidth = getCharWidthForNodeType(type);
margins.charHeight = getCharHeightForNodeType(type);
return margins;
}
@@ -211,8 +232,8 @@ GraphViewStyle::NodeMargins GraphViewStyle::getMarginsOfExpandToggleNode()
{
NodeMargins margins;
margins.left = margins.right = margins.top = margins.bottom = 11;
margins.minWidth = 0;
margins.left = margins.right = margins.top = margins.bottom = 7;
margins.minWidth = margins.charHeight = getFontSizeOfExpandToggleNode();
return margins;
}
@@ -364,7 +385,7 @@ GraphViewStyle::NodeStyle GraphViewStyle::getStyleOfExpandToggleNode()
style.color = "#FFFFFF";
style.borderColor = "#00000000";
style.cornerRadius = 12;
style.cornerRadius = 100;
style.fontName = getFontNameOfExpandToggleNode();
style.fontSize = getFontSizeOfExpandToggleNode();
@@ -466,4 +487,9 @@ size_t GraphViewStyle::s_gridCellSize = 5;
size_t GraphViewStyle::s_gridCellPadding = 10;
std::map<Node::NodeType, float> GraphViewStyle::s_charWidths;
std::map<Node::NodeType, float> GraphViewStyle::s_charHeights;
std::shared_ptr<GraphViewStyleImpl> GraphViewStyle::s_impl;
int GraphViewStyle::s_fontSize;
std::string GraphViewStyle::s_fontName;
+10
View File
@@ -29,7 +29,9 @@ public:
int spacingY;
int minWidth;
float charWidth;
float charHeight;
};
struct NodeStyle
@@ -81,7 +83,10 @@ public:
static std::shared_ptr<GraphViewStyleImpl> getImpl();
static void setImpl(std::shared_ptr<GraphViewStyleImpl> impl);
static void loadStyleSettings();
static float getCharWidthForNodeType(Node::NodeType type);
static float getCharHeightForNodeType(Node::NodeType type);
static size_t getFontSizeForNodeType(Node::NodeType type);
static size_t getFontSizeOfAccessNode();
@@ -110,7 +115,12 @@ public:
private:
static std::map<Node::NodeType, float> s_charWidths;
static std::map<Node::NodeType, float> s_charHeights;
static std::shared_ptr<GraphViewStyleImpl> s_impl;
static int s_fontSize;
static std::string s_fontName;
};
#endif // GRAPH_VIEW_STYLE_H
@@ -7,6 +7,7 @@ class GraphViewStyleImpl
{
public:
virtual float getCharWidthForNodeType(Node::NodeType type) = 0;
virtual float getCharHeightForNodeType(Node::NodeType type) = 0;
};
#endif // GRAPH_VIEW_STYLE_IMPL_H
+20 -20
View File
@@ -26,6 +26,26 @@ bool ApplicationSettings::filterUndefinedNodesFromGraph() const
return getValue<bool>("FilterUndefinedNodesFromGraph", false);
}
std::string ApplicationSettings::getFontName() const
{
return getValue<std::string>("application/font_name", "Source Code Pro");
}
void ApplicationSettings::setFontName(const std::string& fontName)
{
setValue<std::string>("application/font_name", fontName);
}
int ApplicationSettings::getFontSize() const
{
return getValue<int>("application/font_size", 14);
}
void ApplicationSettings::setFontSize(int fontSize)
{
setValue<int>("application/font_size", fontSize);
}
int ApplicationSettings::getCodeTabWidth() const
{
return getValue<int>("code/TabWidth", 4);
@@ -36,26 +56,6 @@ void ApplicationSettings::setCodeTabWidth(int codeTabWidth)
setValue<int>("code/TabWidth", codeTabWidth);
}
std::string ApplicationSettings::getCodeFontName() const
{
return getValue<std::string>("code/FontName", "Courier");
}
void ApplicationSettings::setCodeFontName(const std::string& codeFontName)
{
setValue<std::string>("code/FontName", codeFontName);
}
int ApplicationSettings::getCodeFontSize() const
{
return getValue<int>("code/FontSize", 12);
}
void ApplicationSettings::setCodeFontSize(int codeFontSize)
{
setValue<int>("code/FontSize", codeFontSize);
}
int ApplicationSettings::getCodeSnippetSnapRange() const
{
return getValue<int>("code/snippet/snap_range", 4);
+7 -6
View File
@@ -19,16 +19,17 @@ public:
std::string getStartupProjectFilePath() const;
bool filterUndefinedNodesFromGraph() const;
// application
std::string getFontName() const;
void setFontName(const std::string& fontName);
int getFontSize() const;
void setFontSize(int fontSize);
// code
int getCodeTabWidth() const;
void setCodeTabWidth(int codeTabWidth);
std::string getCodeFontName() const;
void setCodeFontName(const std::string& codeFontName);
int getCodeFontSize() const;
void setCodeFontSize(int codeFontSize);
int getCodeSnippetSnapRange() const;
void setCodeSnippetSnapRange(int range);
+15 -1
View File
@@ -14,16 +14,29 @@ bool Settings::load(const std::string& filePath)
if (FileSystem::exists(filePath))
{
m_config = ConfigManager::createAndLoad(TextAccess::createFromFile(filePath));
m_filePath = filePath;
return true;
}
else
{
m_config = ConfigManager::createEmpty();
clear();
LOG_WARNING("File for Settings not found.");
return false;
}
}
void Settings::save()
{
if (m_config.get() && m_filePath.size())
{
m_config->save(m_filePath);
}
else
{
LOG_WARNING("Settings were not saved.");
}
}
void Settings::save(const std::string& filePath)
{
if (m_config)
@@ -39,6 +52,7 @@ void Settings::save(const std::string& filePath)
void Settings::clear()
{
m_config = ConfigManager::createEmpty();
m_filePath.clear();
}
Settings::Settings()
+2
View File
@@ -13,6 +13,7 @@ public:
virtual ~Settings();
bool load(const std::string& filePath);
void save();
void save(const std::string& filePath);
void clear();
@@ -32,6 +33,7 @@ protected:
bool setValues(const std::string& key, std::vector<T> values);
private:
std::string m_filePath;
std::shared_ptr<ConfigManager> m_config;
};
@@ -6,7 +6,8 @@
class MessageRefresh: public Message<MessageRefresh>
{
public:
MessageRefresh()
MessageRefresh(bool uiOnly = false)
: uiOnly(uiOnly)
{
}
@@ -14,6 +15,8 @@ public:
{
return "MessageRefresh";
}
const bool uiOnly;
};
#endif // MESSAGE_REFRESH_H
@@ -0,0 +1,23 @@
#ifndef MESSAGE_ZOOM_H
#define MESSAGE_ZOOM_H
#include "utility/messaging/Message.h"
class MessageZoom
: public Message<MessageZoom>
{
public:
MessageZoom(bool zoomIn)
: zoomIn(zoomIn)
{
}
static const std::string getStaticType()
{
return "MessageZoom";
}
const bool zoomIn;
};
#endif // MESSAGE_ZOOM_H