Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add menu option to change editor font for #645 #866

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions src/robomongo/gui/GuiRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Robomongo
/**
* @brief This is a private constructor, because GuiRegistry is a singleton
*/
GuiRegistry::GuiRegistry()
GuiRegistry::GuiRegistry(): textFont(NULL)
{
}

Expand Down Expand Up @@ -292,7 +292,7 @@ namespace Robomongo
return mainWindowIc;
}

const QFont &GuiRegistry::font() const
void GuiRegistry::loadFont()
{
QString family = AppRegistry::instance().settingsManager()->textFontFamily();
if (family.isEmpty()) {
Expand All @@ -316,12 +316,26 @@ namespace Robomongo
#endif
}

if (textFont == NULL) {
textFont = new QFont(family, pointSize);
}
else {
//This is a reload
textFont->setFamily(family);
textFont->setPointSize(pointSize);
}

static QFont textFont = QFont(family, pointSize);
#if defined(Q_OS_UNIX)
textFont.setFixedPitch(true);
textFont->setFixedPitch(true);
#endif
}

return textFont;
const QFont &GuiRegistry::font()
{
if (textFont == NULL)
{
loadFont();
}
return *textFont;
}
}
6 changes: 5 additions & 1 deletion src/robomongo/gui/GuiRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,12 @@ namespace Robomongo

const QBrush &typeBrush() const;

const QFont &font() const;
void loadFont();
const QFont &font();

private:
QFont* textFont;

/**
* @brief Private, because this is singleton
*/
Expand Down
67 changes: 43 additions & 24 deletions src/robomongo/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <QLabel>
#include <QStatusBar>
#include <QHBoxLayout>
#include <QFontDialog>

#include "robomongo/core/settings/SettingsManager.h"
#include "robomongo/core/domain/MongoServer.h"
Expand Down Expand Up @@ -52,13 +53,13 @@ namespace
Robomongo::AppRegistry::instance().settingsManager()->setViewMode(mode);
Robomongo::AppRegistry::instance().settingsManager()->save();
}

void saveAutoExpand(bool isExpand)
{
Robomongo::AppRegistry::instance().settingsManager()->setAutoExpand(isExpand);
Robomongo::AppRegistry::instance().settingsManager()->save();
}

void saveAutoExec(bool isAutoExec)
{
Robomongo::AppRegistry::instance().settingsManager()->setAutoExec(isAutoExec);
Expand Down Expand Up @@ -156,7 +157,7 @@ namespace Robomongo
_connectButton->setFocusPolicy(Qt::NoFocus);
_connectButton->setToolTip(QString("Connect to local or remote MongoDB instance <b>(%1 + N)</b>").arg(controlKey));
_connectButton->setToolButtonStyle(Qt::ToolButtonIconOnly);

#if !defined(Q_OS_MAC)
_connectButton->setMenu(_connectionsMenu);
_connectButton->setPopupMode(QToolButton::MenuButtonPopup);
Expand Down Expand Up @@ -266,7 +267,7 @@ namespace Robomongo
defaultViewModeMenu->addAction(treeModeAction);
defaultViewModeMenu->addAction(tableModeAction);
defaultViewModeMenu->addAction(textModeAction);

optionsMenu->addSeparator();

QActionGroup *modeGroup = new QActionGroup(this);
Expand Down Expand Up @@ -350,6 +351,10 @@ namespace Robomongo
autocompletionGroup->addAction(autocompletionNoCollectionNamesAction);
autocompletionGroup->addAction(autocompletionNoneAction);

QAction* enterEditorFontAction = new QAction("Select Editor Font...", this);
VERIFY(connect(enterEditorFontAction, SIGNAL(triggered()), this, SLOT(enterEditorFont())));
optionsMenu->addAction(enterEditorFontAction);

QAction *loadMongoRcJs = new QAction("Load .mongorc.js",this);
loadMongoRcJs->setCheckable(true);
loadMongoRcJs->setChecked(AppRegistry::instance().settingsManager()->loadMongoRcJs());
Expand All @@ -376,7 +381,7 @@ namespace Robomongo
disabelConnectionShortcuts->setChecked(AppRegistry::instance().settingsManager()->disableConnectionShortcuts());
VERIFY(connect(disabelConnectionShortcuts, SIGNAL(triggered()), this, SLOT(setDisableConnectionShortcuts())));
optionsMenu->addAction(disabelConnectionShortcuts);

QAction *autoExec = new QAction(tr("Automatically execute code in new tab"),this);
autoExec->setCheckable(true);
autoExec->setChecked(AppRegistry::instance().settingsManager()->autoExec());
Expand Down Expand Up @@ -516,7 +521,7 @@ namespace Robomongo
styleAction->setCheckable(true);
styleAction->setChecked(style == currentStyle);
styleGroup->addAction(styleAction);
styles->addAction(styleAction);
styles->addAction(styleAction);
}
}

Expand Down Expand Up @@ -713,7 +718,7 @@ namespace Robomongo
QAction *send = qobject_cast<QAction*>(sender());
saveAutoExpand(send->isChecked());
}

void MainWindow::toggleAutoExec()
{
QAction *send = qobject_cast<QAction*>(sender());
Expand All @@ -725,7 +730,21 @@ namespace Robomongo
QAction *send = qobject_cast<QAction*>(sender());
saveLineNumbers(send->isChecked());
}


void MainWindow::enterEditorFont()
{
bool ok;
QFont font = QFontDialog::getFont(&ok, GuiRegistry::instance().font(), this);

if (ok) {
AppRegistry::instance().settingsManager()->setTextFontFamily(font.family());
AppRegistry::instance().settingsManager()->setTextFontPointSize(font.pointSize());
AppRegistry::instance().settingsManager()->save();

GuiRegistry::instance().loadFont();
}
}

void MainWindow::executeScript()
{
QueryWidget *widget = _workArea->currentQueryWidget();
Expand Down Expand Up @@ -915,37 +934,37 @@ namespace Robomongo
QWidget *titleWidget = new QWidget(this); // this lines simply remove
explorerDock->setTitleBarWidget(titleWidget); // title bar widget.
explorerDock->setVisible(AppRegistry::instance().settingsManager()->toolbars()["explorer"].toBool());

QAction *actionExp = explorerDock->toggleViewAction();
// Adjust any parameter you want.
// Adjust any parameter you want.
actionExp->setText(QString("&Explorer"));
actionExp->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_E));
actionExp->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_E));
actionExp->setStatusTip(QString("Press to show/hide Database Explorer panel."));
actionExp->setChecked(explorerDock->isVisible());
VERIFY(connect(actionExp, SIGNAL(triggered(bool)), this, SLOT(onExplorerVisibilityChanged(bool))));
// Install action in the menu.
// Install action in the menu.
_viewMenu->addAction(actionExp);

addDockWidget(Qt::LeftDockWidgetArea, explorerDock);

LogWidget *log = new LogWidget(this);
LogWidget *log = new LogWidget(this);
VERIFY(connect(&Logger::instance(), SIGNAL(printed(const QString&, mongo::LogLevel)), log, SLOT(addMessage(const QString&, mongo::LogLevel))));
_logDock = new QDockWidget(tr("Logs"));
_logDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea | Qt::TopDockWidgetArea);
_logDock->setWidget(log);
_logDock->setFeatures(QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetMovable);
_logDock->setVisible(AppRegistry::instance().settingsManager()->toolbars()["logs"].toBool());

QAction *action = _logDock->toggleViewAction();
// Adjust any parameter you want.
// Adjust any parameter you want.
action->setText(QString("&Logs"));
action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_L));
action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_L));
//action->setStatusTip(QString("Press to show/hide Logs panel.")); //commented for now because this message hides Logs button in status bar :)
action->setChecked(_logDock->isVisible());
VERIFY(connect(action, SIGNAL(triggered(bool)), this, SLOT(onLogsVisibilityChanged(bool))));
// Install action in the menu.
_viewMenu->addAction(action);

addDockWidget(Qt::BottomDockWidgetArea, _logDock);
}

Expand Down Expand Up @@ -974,32 +993,32 @@ namespace Robomongo

setCentralWidget(window);
}

void MainWindow::onConnectToolbarVisibilityChanged(bool isVisible)
{
AppRegistry::instance().settingsManager()->setToolbarSettings("connect", isVisible);
AppRegistry::instance().settingsManager()->save();
}

void MainWindow::onOpenSaveToolbarVisibilityChanged(bool isVisible)
{
AppRegistry::instance().settingsManager()->setToolbarSettings("open_save", isVisible);
AppRegistry::instance().settingsManager()->save();
}

void MainWindow::onExecToolbarVisibilityChanged(bool isVisible)
{
AppRegistry::instance().settingsManager()->setToolbarSettings("exec", isVisible);
AppRegistry::instance().settingsManager()->save();
}
void MainWindow::onExplorerVisibilityChanged(bool isVisible)

void MainWindow::onExplorerVisibilityChanged(bool isVisible)
{
AppRegistry::instance().settingsManager()->setToolbarSettings("explorer", isVisible);
AppRegistry::instance().settingsManager()->save();
}
void MainWindow::onLogsVisibilityChanged(bool isVisible)

void MainWindow::onLogsVisibilityChanged(bool isVisible)
{
AppRegistry::instance().settingsManager()->setToolbarSettings("logs", isVisible);
AppRegistry::instance().settingsManager()->save();
Expand Down
1 change: 1 addition & 0 deletions src/robomongo/gui/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ namespace Robomongo
void toggleAutoExpand();
void toggleAutoExec();
void toggleLineNumbers();
void enterEditorFont();
void executeScript();
void stopScript();
void toggleFullScreen2();
Expand Down