Skip to content

Commit

Permalink
Modify status bar as discussed
Browse files Browse the repository at this point in the history
  • Loading branch information
J5lx committed Mar 2, 2021
1 parent 4c85f61 commit 036392c
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 91 deletions.
9 changes: 4 additions & 5 deletions app/src/mainwindow2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ MainWindow2::MainWindow2(QWidget* parent) :
ui->scribbleArea->init();

ui->statusBar->setEditor(mEditor);
ui->statusBar->updateLayerStatus();
ui->statusBar->updateZoomStatus();
ui->statusBar->setVisible(mEditor->preference()->isOn(SETTING::SHOW_STATUS_BAR));

mCommands = new ActionCommands(this);
mCommands->setCore(mEditor);
Expand Down Expand Up @@ -323,6 +323,8 @@ void MainWindow2::createMenus()
connect(mEditor->view(), &ViewManager::viewFlipped, this, &MainWindow2::viewFlipped);

PreferenceManager* prefs = mEditor->preference();
connect(ui->actionStatusBar, &QAction::triggered, ui->statusBar, &QStatusBar::setVisible);
bindPreferenceSetting(ui->actionStatusBar, prefs, SETTING::SHOW_STATUS_BAR);
bindPreferenceSetting(ui->actionGrid, prefs, SETTING::GRID);
bindPreferenceSetting(ui->actionOnionPrev, prefs, SETTING::PREV_ONION);
bindPreferenceSetting(ui->actionOnionNext, prefs, SETTING::NEXT_ONION);
Expand Down Expand Up @@ -1157,6 +1159,7 @@ void MainWindow2::setupKeyboardShortcuts()
ui->actionGrid->setShortcut(cmdKeySeq(CMD_GRID));
ui->actionOnionPrev->setShortcut(cmdKeySeq(CMD_ONIONSKIN_PREV));
ui->actionOnionNext->setShortcut(cmdKeySeq(CMD_ONIONSKIN_NEXT));
ui->actionStatusBar->setShortcut(cmdKeySeq(CMD_TOGGLE_STATUS_BAR));

ui->actionPlay->setShortcut(cmdKeySeq(CMD_PLAY));
ui->actionLoop->setShortcut(cmdKeySeq(CMD_LOOP));
Expand Down Expand Up @@ -1419,10 +1422,6 @@ void MainWindow2::makeConnections(Editor* editor, StatusBar *statusBar)
connect(editor->tools(), &ToolManager::toolChanged, statusBar, &StatusBar::updateToolStatus);
connect(editor->tools()->getTool(POLYLINE), &BaseTool::isActiveChanged, statusBar, &StatusBar::updateToolStatus);

connect(editor->layers(), &LayerManager::layerCountChanged, statusBar, QOverload<>::of(&StatusBar::updateLayerStatus));
connect(editor->layers(), &LayerManager::currentLayerChanged, statusBar, QOverload<int>::of(&StatusBar::updateLayerStatus));
connect(statusBar, &StatusBar::layerIndexChanged, editor->layers(), QOverload<int>::of(&LayerManager::setCurrentLayer));

connect(editor->view(), &ViewManager::viewChanged, statusBar, &StatusBar::updateZoomStatus);
connect(statusBar, &StatusBar::zoomChanged, editor->view(), &ViewManager::scale);
}
Expand Down
1 change: 1 addition & 0 deletions app/src/shortcutspage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ static QString getHumanReadableShortcutName(const QString& cmdName)
{CMD_SAVE_AS, ShortcutsPage::tr("Save File As", "Shortcut")},
{CMD_SAVE_FILE, ShortcutsPage::tr("Save File", "Shortcut")},
{CMD_SELECT_ALL, ShortcutsPage::tr("Select All", "Shortcut")},
{CMD_TOGGLE_STATUS_BAR, ShortcutsPage::tr("Toggle Status Bar Visibility", "Shortcut")},
{CMD_TOGGLE_COLOR_INSPECTOR, ShortcutsPage::tr("Toggle Color Inspector Window Visibility", "Shortcut")},
{CMD_TOGGLE_COLOR_LIBRARY, ShortcutsPage::tr("Toggle Color Palette Window Visibility", "Shortcut")},
{CMD_TOGGLE_COLOR_WHEEL, ShortcutsPage::tr("Toggle Color Box Window Visibility", "Shortcut")},
Expand Down
60 changes: 5 additions & 55 deletions app/src/statusbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,10 @@ StatusBar::StatusBar(QWidget *parent) : QStatusBar(parent)
addWidget(mToolLabel);

mModifiedLabel = new QLabel(this);
mModifiedLabel->setPixmap(QPixmap(":/icons/save.png"));
updateModifiedStatus(false);
addPermanentWidget(mModifiedLabel);

mLayerBox = new QComboBox(this);
connect(mLayerBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &StatusBar::layerIndexChanged);
addPermanentWidget(mLayerBox);

mZoomBox = new QComboBox(this);
mZoomBox->addItems(QStringList()
<< "10000.0%" << "6400.0%" << "1600.0%" << "800.0%" << "400.0%" << "200.0%"
Expand All @@ -56,6 +53,7 @@ StatusBar::StatusBar(QWidget *parent) : QStatusBar(parent)
if (mZoomBox->count() == mZoomBox->maxCount())
{
// Keep the size of the list reasonable by preventing user entries
// insertPolicy is unsuitable as it prevents entering custom values at all
mZoomBox->removeItem(mZoomBox->maxCount() - 1);
}
emit zoomChanged(QString(currentText).remove('%').toDouble() / 100);
Expand Down Expand Up @@ -148,61 +146,13 @@ void StatusBar::updateToolStatus(ToolType tool)

void StatusBar::updateModifiedStatus(bool modified)
{
static QPixmap modifiedIcon(":/icons/saveas.png"),
unmodifiedIcon(":/icons/save.png");

mModifiedLabel->setDisabled(!modified);
if (modified)
{
mModifiedLabel->setPixmap(modifiedIcon);
mModifiedLabel->setToolTip(tr("The file has unsaved changes"));
mModifiedLabel->setToolTip(tr("This file has unsaved changes"));
return;
}
mModifiedLabel->setPixmap(unmodifiedIcon);
mModifiedLabel->setToolTip(tr("The file has no unsaved changes"));
}

void StatusBar::updateLayerStatus()
{
Q_ASSERT(mEditor);
static QIcon bitmapIcon(":/icons/layer-bitmap.png"),
vectorIcon(":/icons/layer-vector.png"),
soundIcon(":/icons/layer-sound.png"),
cameraIcon(":/icons/layer-camera.png");

QSignalBlocker b(mLayerBox);
mLayerBox->clear();
for (int i = 0; i < mEditor->layers()->count(); i++)
{
Layer *layer = mEditor->layers()->getLayer(i);
mLayerBox->addItem(layer->name());
switch (layer->type())
{
case Layer::BITMAP:
mLayerBox->setItemIcon(i, bitmapIcon);
break;
case Layer::VECTOR:
mLayerBox->setItemIcon(i, vectorIcon);
break;
case Layer::SOUND:
mLayerBox->setItemIcon(i, soundIcon);
break;
case Layer::CAMERA:
mLayerBox->setItemIcon(i, cameraIcon);
break;
case Layer::MOVIE:
case Layer::UNDEFINED:
// no icon
break;
}
}
mLayerBox->setCurrentIndex(mEditor->layers()->currentLayerIndex());
}

void StatusBar::updateLayerStatus(int layer)
{
Q_ASSERT(mEditor);
mLayerBox->setItemText(layer, mEditor->layers()->getLayer(layer)->name());
mLayerBox->setCurrentIndex(layer);
mModifiedLabel->setToolTip(tr("This file has no unsaved changes"));
}

void StatusBar::updateZoomStatus()
Expand Down
26 changes: 0 additions & 26 deletions app/src/statusbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,36 +65,12 @@ public slots:
*/
void updateModifiedStatus(bool modified);

/**
* Completely rebuilds the layer status for all layers.
*
* This is necessary when layers are added, removed or reordered.
*
* @see updateLayerStatus(int)
*/
void updateLayerStatus();

/**
* Updates the current layer.
*
* @param layer The index of the currently active layer
*
* @see updateLayerStatus()
*/
void updateLayerStatus(int layer);

/**
* Updates the zoom level displayed in the status bar.
*/
void updateZoomStatus();

signals:
/**
* This signal is sent when the user selects a new active layer through the status bar.
*
* @param index The index of the newly selected layer
*/
void layerIndexChanged(int index);

/**
* This signal is sent when the user chooses a new zoom level through the status bar.
Expand All @@ -113,8 +89,6 @@ public slots:
QLabel *mToolLabel = nullptr;
/** Label indicating that the current file contains unsaved changes */
QLabel *mModifiedLabel = nullptr;
/** Combo box for the active layer */
QComboBox *mLayerBox = nullptr;
/** Combo box for choosing pre-defined or custom zoom levels */
QComboBox *mZoomBox = nullptr;
/** Slider for adjusting the zoom level */
Expand Down
18 changes: 13 additions & 5 deletions app/ui/mainwindow2.ui
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@
<addaction name="menuImport"/>
<addaction name="menuExport"/>
<addaction name="separator"/>
<addaction name="separator"/>
<addaction name="actionExit"/>
</widget>
<widget class="QMenu" name="menuEdit">
Expand Down Expand Up @@ -173,12 +172,11 @@
<addaction name="menuOnion_Skin"/>
<addaction name="menuLayer_Visibility"/>
<addaction name="separator"/>
<addaction name="separator"/>
<addaction name="actionGrid"/>
<addaction name="separator"/>
<addaction name="separator"/>
<addaction name="separator"/>
<addaction name="actionPreview"/>
<addaction name="separator"/>
<addaction name="actionStatusBar"/>
</widget>
<widget class="QMenu" name="menuAnimation">
<property name="title">
Expand Down Expand Up @@ -240,7 +238,6 @@
<addaction name="actionDelete_Current_Layer"/>
<addaction name="separator"/>
<addaction name="menuChange_line_color"/>
<addaction name="separator"/>
</widget>
<widget class="QMenu" name="menuHelp">
<property name="title">
Expand Down Expand Up @@ -1117,6 +1114,17 @@
<string>Reset Rotation</string>
</property>
</action>
<action name="actionStatusBar">
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="text">
<string>Status Bar</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
Expand Down
1 change: 1 addition & 0 deletions core_lib/data/resources/kb.ini
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ CmdPreview=Alt+P
CmdGrid=G
CmdOnionSkinPrevious=O
CmdOnionSkinNext=Alt+O
CmdToggleStatusBar=
CmdPlay=Ctrl+Return
CmdLoop=Ctrl+L
CmdFlipInBetween=Alt+Z
Expand Down
4 changes: 4 additions & 0 deletions core_lib/src/managers/preferencemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ void PreferenceManager::loadPrefs()
set(SETTING::ROTATION_INCREMENT, settings.value(SETTING_ROTATION_INCREMENT, 15).toInt());

set(SETTING::WINDOW_OPACITY, settings.value(SETTING_WINDOW_OPACITY, 0).toInt());
set(SETTING::SHOW_STATUS_BAR, settings.value(SETTING_SHOW_STATUS_BAR, true).toBool());
set(SETTING::CURVE_SMOOTHING, settings.value(SETTING_CURVE_SMOOTHING, 20).toInt());

set(SETTING::BACKGROUND_STYLE, settings.value(SETTING_BACKGROUND_STYLE, "white").toString());
Expand Down Expand Up @@ -343,6 +344,9 @@ void PreferenceManager::set(SETTING option, bool value)
QSettings settings(PENCIL2D, PENCIL2D);
switch (option)
{
case SETTING::SHOW_STATUS_BAR:
settings.setValue(SETTING_SHOW_STATUS_BAR, value);
break;
case SETTING::ANTIALIAS:
settings.setValue(SETTING_ANTIALIAS, value);
break;
Expand Down
1 change: 1 addition & 0 deletions core_lib/src/managers/preferencemanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ enum class SETTING
DOTTED_CURSOR,
HIGH_RESOLUTION,
WINDOW_OPACITY,
SHOW_STATUS_BAR,
CURVE_SMOOTHING,
BACKGROUND_STYLE,
AUTO_SAVE,
Expand Down
2 changes: 2 additions & 0 deletions core_lib/src/util/pencildef.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ const static int MaxFramesBound = 9999;
#define CMD_GRID "CmdGrid"
#define CMD_ONIONSKIN_PREV "CmdOnionSkinPrevious"
#define CMD_ONIONSKIN_NEXT "CmdOnionSkinNext"
#define CMD_TOGGLE_STATUS_BAR "CmdToggleStatusBar"
#define CMD_PLAY "CmdPlay"
#define CMD_LOOP "CmdLoop"
#define CMD_FLIP_INBETWEEN "CmdFlipInBetween"
Expand Down Expand Up @@ -210,6 +211,7 @@ const static int MaxFramesBound = 9999;
#define SETTING_WINDOW_OPACITY "WindowOpacity"
#define SETTING_WINDOW_GEOMETRY "WindowGeometry"
#define SETTING_WINDOW_STATE "WindowState"
#define SETTING_SHOW_STATUS_BAR "ShowStatusBar"
#define SETTING_CURVE_SMOOTHING "CurveSmoothing"
#define SETTING_DISPLAY_EFFECT "RenderEffect"
#define SETTING_SHORT_SCRUB "ShortScrub"
Expand Down

0 comments on commit 036392c

Please sign in to comment.