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:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user