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
+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)
);
}