diff --git a/app/app.pro b/app/app.pro index fa229e90d..0aeeba70a 100644 --- a/app/app.pro +++ b/app/app.pro @@ -106,7 +106,9 @@ HEADERS += \ src/checkupdatesdialog.h \ src/presetdialog.h \ src/commandlineparser.h \ - src/commandlineexporter.h + src/commandlineexporter.h \ + src/statusbar.h \ + src/elidedlabel.h SOURCES += \ src/importlayersdialog.cpp \ @@ -150,7 +152,9 @@ SOURCES += \ src/presetdialog.cpp \ src/app_util.cpp \ src/commandlineparser.cpp \ - src/commandlineexporter.cpp + src/commandlineexporter.cpp \ + src/statusbar.cpp \ + src/elidedlabel.cpp FORMS += \ ui/importimageseqpreview.ui \ diff --git a/app/src/elidedlabel.cpp b/app/src/elidedlabel.cpp new file mode 100644 index 000000000..c27209e4d --- /dev/null +++ b/app/src/elidedlabel.cpp @@ -0,0 +1,132 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "elidedlabel.h" + +#include +#include +#include + + +ElidedLabel::ElidedLabel(QWidget *parent) + : QFrame(parent) + , elided(false) +{ + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); +} + +//! [0] +ElidedLabel::ElidedLabel(const QString &text, QWidget *parent) : + ElidedLabel(parent) +{ + content = text; +} +//! [0] + +//! [1] +void ElidedLabel::setText(const QString &newText) +{ + content = newText; + update(); +} +//! [1] + +QSize ElidedLabel::sizeHint() const +{ + return fontMetrics().size(0, content); +} + +//! [2] +void ElidedLabel::paintEvent(QPaintEvent *event) +{ + QFrame::paintEvent(event); + + QPainter painter(this); + QFontMetrics fontMetrics = painter.fontMetrics(); + + bool didElide = false; + int lineSpacing = fontMetrics.lineSpacing(); + int y = 0; + + QTextLayout textLayout(content, painter.font()); + textLayout.beginLayout(); + forever { + QTextLine line = textLayout.createLine(); + + if (!line.isValid()) + break; + + line.setLineWidth(width()); + int nextLineY = y + lineSpacing; + + if (height() >= nextLineY + lineSpacing) { + line.draw(&painter, QPoint(0, y)); + y = nextLineY; + //! [2] + //! [3] + } else { + QString lastLine = content.mid(line.textStart()); + QString elidedLastLine = fontMetrics.elidedText(lastLine, Qt::ElideRight, width()); + painter.drawText(QPoint(0, y + fontMetrics.ascent()), elidedLastLine); + line = textLayout.createLine(); + didElide = line.isValid(); + break; + } + } + textLayout.endLayout(); + //! [3] + + //! [4] + if (didElide != elided) { + elided = didElide; + emit elisionChanged(didElide); + } +} +//! [4] diff --git a/app/src/elidedlabel.h b/app/src/elidedlabel.h new file mode 100644 index 000000000..36c21ff14 --- /dev/null +++ b/app/src/elidedlabel.h @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef ELIDEDLABEL_H +#define ELIDEDLABEL_H + +#include +#include + +//! [0] +class ElidedLabel : public QFrame +{ + Q_OBJECT + Q_PROPERTY(QString text READ text WRITE setText) + Q_PROPERTY(bool isElided READ isElided) + +public: + explicit ElidedLabel(QWidget *parent = nullptr); + explicit ElidedLabel(const QString &text, QWidget *parent = nullptr); + + void setText(const QString &text); + const QString & text() const { return content; } + bool isElided() const { return elided; } + + virtual QSize sizeHint() const override; + +protected: + void paintEvent(QPaintEvent *event) override; + +signals: + void elisionChanged(bool elided); + +private: + bool elided; + QString content; +}; +//! [0] + +#endif // TEXTWRAPPINGWIDGET_H diff --git a/app/src/mainwindow2.cpp b/app/src/mainwindow2.cpp index 17acfc75a..ec9fecabf 100644 --- a/app/src/mainwindow2.cpp +++ b/app/src/mainwindow2.cpp @@ -29,7 +29,6 @@ GNU General Public License for more details. #include #include #include -#include // core_lib headers #include "pencildef.h" @@ -110,6 +109,10 @@ MainWindow2::MainWindow2(QWidget* parent) : ui->scribbleArea->setEditor(mEditor); ui->scribbleArea->init(); + ui->statusBar->setEditor(mEditor); + ui->statusBar->updateZoomStatus(); + ui->statusBar->setVisible(mEditor->preference()->isOn(SETTING::SHOW_STATUS_BAR)); + mCommands = new ActionCommands(this); mCommands->setCore(mEditor); @@ -119,15 +122,10 @@ MainWindow2::MainWindow2(QWidget* parent) : readSettings(); - mZoomLabel = new QLabel(""); - ui->statusbar->addWidget(mZoomLabel); - - updateZoomLabel(); selectionChanged(); connect(mEditor, &Editor::needSave, this, &MainWindow2::autoSave); connect(mToolBox, &ToolBoxWidget::clearButtonClicked, mEditor, &Editor::clearCurrentFrame); - connect(mEditor->view(), &ViewManager::viewChanged, this, &MainWindow2::updateZoomLabel); mEditor->tools()->setDefaultTool(); ui->background->init(mEditor->preference()); @@ -226,6 +224,7 @@ void MainWindow2::createDockWidgets() makeConnections(mEditor, mColorPalette); makeConnections(mEditor, mToolOptions); makeConnections(mEditor, mDisplayOptionWidget); + makeConnections(mEditor, ui->statusBar); for (BaseDockWidget* w : mDockWidgets) { @@ -326,6 +325,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); @@ -423,7 +424,9 @@ void MainWindow2::setOpacity(int opacity) void MainWindow2::updateSaveState() { - setWindowModified(mEditor->currentBackup() != mBackupAtSave); + const bool hasUnsavedChanges = mEditor->currentBackup() != mBackupAtSave; + setWindowModified(hasUnsavedChanges); + ui->statusBar->updateModifiedStatus(hasUnsavedChanges); } void MainWindow2::clearRecentFilesList() @@ -617,6 +620,7 @@ bool MainWindow2::openObject(const QString& strFilePath) setWindowTitle(mEditor->object()->filePath().prepend("[*]")); setWindowModified(false); + ui->statusBar->updateModifiedStatus(false); progress.setValue(progress.maximum()); @@ -1180,6 +1184,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)); @@ -1437,10 +1442,12 @@ void MainWindow2::makeConnections(Editor* pEditor, ColorPaletteWidget* pColorPal connect(pColorManager, &ColorManager::colorNumberChanged, pColorPalette, &ColorPaletteWidget::selectColorNumber); } -void MainWindow2::updateZoomLabel() +void MainWindow2::makeConnections(Editor* editor, StatusBar *statusBar) { - qreal zoom = mEditor->view()->scaling() * 100.f; - mZoomLabel->setText(tr("Zoom: %1%").arg(zoom, 0, 'f', 1)); + connect(editor->tools(), &ToolManager::toolChanged, statusBar, &StatusBar::updateToolStatus); + connect(editor->tools()->getTool(POLYLINE), &BaseTool::isActiveChanged, statusBar, &StatusBar::updateToolStatus); + + connect(editor->view(), &ViewManager::viewChanged, statusBar, &StatusBar::updateZoomStatus); } void MainWindow2::changePlayState(bool isPlaying) diff --git a/app/src/mainwindow2.h b/app/src/mainwindow2.h index 94ecddb9d..e78858199 100644 --- a/app/src/mainwindow2.h +++ b/app/src/mainwindow2.h @@ -42,8 +42,8 @@ class ActionCommands; class ImportImageSeqDialog; class BackupElement; class LayerOpacityDialog; -class QLabel; class PegBarAlignmentDialog; +class StatusBar; enum class SETTING; @@ -121,7 +121,6 @@ public slots: void createMenus(); void setupKeyboardShortcuts(); void clearKeyboardShortcuts(); - void updateZoomLabel(); bool loadMostRecent(); bool tryLoadPreset(); @@ -144,6 +143,7 @@ public slots: void makeConnections(Editor*, DisplayOptionWidget*); void makeConnections(Editor*, ToolOptionWidget*); void makeConnections(Editor*, OnionSkinWidget*); + void makeConnections(Editor*, StatusBar*); bool tryRecoverUnsavedProject(); void startProjectRecovery(int result); @@ -177,9 +177,6 @@ public slots: // a hack for MacOS because closeEvent fires twice bool m2ndCloseEvent = false; - // statusbar widgets - QLabel* mZoomLabel = nullptr; - // Whether to suppress the auto save dialog due to internal work bool mSuppressAutoSaveDialog = false; diff --git a/app/src/shortcutspage.cpp b/app/src/shortcutspage.cpp index 1049c76aa..b3c09698c 100644 --- a/app/src/shortcutspage.cpp +++ b/app/src/shortcutspage.cpp @@ -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")}, diff --git a/app/src/statusbar.cpp b/app/src/statusbar.cpp new file mode 100644 index 000000000..db00a9a69 --- /dev/null +++ b/app/src/statusbar.cpp @@ -0,0 +1,184 @@ +/* + +Pencil2D - Traditional Animation Software +Copyright (C) 2020 Jakob Gahde + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +*/ + +#include +#include +#include +#include + +#include "editor.h" +#include "elidedlabel.h" +#include "layermanager.h" +#include "scribblearea.h" +#include "toolmanager.h" +#include "viewmanager.h" + +#include "statusbar.h" + +StatusBar::StatusBar(QWidget *parent) : QStatusBar(parent) +{ + setContentsMargins(3, 0, 3, 0); + + mToolIcon = new QLabel(this); + addWidget(mToolIcon); + mToolLabel = new ElidedLabel(this); + mToolLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + addWidget(mToolLabel, 1); + + mModifiedLabel = new QLabel(this); + mModifiedLabel->setPixmap(QPixmap(":/icons/save.png")); + updateModifiedStatus(false); + addPermanentWidget(mModifiedLabel); + + QLocale locale; + mZoomBox = new QComboBox(this); + mZoomBox->addItems(QStringList() + << locale.toString(10000., 'f', 1) + locale.percent() + << locale.toString(6400., 'f', 1) + locale.percent() + << locale.toString(1600., 'f', 1) + locale.percent() + << locale.toString(800., 'f', 1) + locale.percent() + << locale.toString(400., 'f', 1) + locale.percent() + << locale.toString(200., 'f', 1) + locale.percent() + << locale.toString(100., 'f', 1) + locale.percent() + << locale.toString(75., 'f', 1) + locale.percent() + << locale.toString(50., 'f', 1) + locale.percent() + << locale.toString(33., 'f', 1) + locale.percent() + << locale.toString(25., 'f', 1) + locale.percent() + << locale.toString(12., 'f', 1) + locale.percent() + << locale.toString(1., 'f', 1) + locale.percent()); + mZoomBox->setMaxCount(mZoomBox->count() + 1); + mZoomBox->setEditable(true); + mZoomBox->lineEdit()->setAlignment(Qt::AlignRight); + connect(mZoomBox, static_cast(&QComboBox::activated), [=](const QString ¤tText) + { + 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(locale.toDouble(QString(currentText).remove(locale.percent())) / 100); + }); + addPermanentWidget(mZoomBox); + + mZoomSlider = new QSlider(Qt::Horizontal, this); + mZoomSlider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); + mZoomSlider->setRange(-20, 20); + mZoomSlider->setTickPosition(QSlider::TicksBelow); + mZoomSlider->setTickInterval(20); + connect(mZoomSlider, &QSlider::valueChanged, [this](int value) + { + emit zoomChanged(std::pow(10, value / 10.)); + }); + addPermanentWidget(mZoomSlider); +} + +void StatusBar::updateToolStatus(ToolType tool) +{ + Q_ASSERT(mEditor); + switch (tool) { + case PENCIL: + mToolLabel->setText(tr("Click to draw. Hold Ctrl and Shift to erase or Alt to select a color from the canvas.")); + break; + case ERASER: + mToolLabel->setText(tr("Click to erase.")); + break; + case SELECT: + mToolLabel->setText(tr("Click and drag to create or modify a selection. Hold Alt to modify its contents or press Backspace to clear them.")); + break; + case MOVE: + if (mEditor->getScribbleArea()->isTemporaryTool()) + { + mToolLabel->setText(tr("Click and drag to move an object.")); + } + else + { + mToolLabel->setText(tr("Click and drag to move an object. Hold Ctrl to rotate.")); + } + break; + case HAND: + mToolLabel->setText(tr("Click and drag to pan. Hold Ctrl to zoom or Alt to rotate.")); + break; + case SMUDGE: + mToolLabel->setText(tr("Click to liquefy pixels or modify a vector line. Hold Alt to smooth.")); + break; + case PEN: + mToolLabel->setText(tr("Click to draw. Hold Ctrl and Shift to erase or Alt to select a color from the canvas.")); + break; + case POLYLINE: + if (mEditor->tools()->getTool(tool)->isActive()) + { + mToolLabel->setText(tr("Click to continue the polyline. Double-click or press enter to complete the line or press Escape to discard it.")); + } + else + { + mToolLabel->setText(tr("Click to create a new polyline. Hold Ctrl and Shift to erase.")); + } + break; + case BUCKET: + mToolLabel->setText(tr("Click to fill an area with the current color. Hold Alt to select a color from the canvas.")); + break; + case EYEDROPPER: + mToolLabel->setText(tr("Click to select a color from the canvas.")); + break; + case BRUSH: + mToolLabel->setText(tr("Click to paint. Hold Ctrl and Shift to erase or Alt to select a color from the canvas.")); + break; + default: + Q_ASSERT(false); + } + + static QPixmap toolIcons[TOOL_TYPE_COUNT]{ + {":icons/new/svg/pencil_detailed.svg"}, + {":icons/new/svg/eraser_detailed.svg"}, + {":icons/new/svg/selection.svg"}, + {":icons/new/svg/arrow.svg"}, + {":icons/new/svg/hand_detailed.svg"}, + {":icons/new/svg/smudge_detailed.svg"}, + {":icons/new/svg/pen_detailed.svg"}, + {":icons/new/svg/line.svg"}, + {":icons/new/svg/bucket_detailed.svg"}, + {":icons/new/svg/eyedropper_detailed.svg"}, + {":icons/new/svg/brush_detailed.svg"} + }; + mToolIcon->setPixmap(toolIcons[tool]); + mToolIcon->setToolTip(BaseTool::TypeName(tool)); +} + +void StatusBar::updateModifiedStatus(bool modified) +{ + mModifiedLabel->setDisabled(!modified); + if (modified) + { + mModifiedLabel->setToolTip(tr("This file has unsaved changes")); + } + else + { + mModifiedLabel->setToolTip(tr("This file has no unsaved changes")); + } +} + +void StatusBar::updateZoomStatus() +{ + Q_ASSERT(mEditor); + + QLocale locale; + QSignalBlocker b1(mZoomBox); + mZoomBox->setCurrentText(locale.toString(mEditor->view()->scaling() * 100, 'f', 1) + locale.percent()); + + QSignalBlocker b2(mZoomSlider); + mZoomSlider->setValue(static_cast(std::round(std::log10(mEditor->view()->scaling()) * 10))); +} diff --git a/app/src/statusbar.h b/app/src/statusbar.h new file mode 100644 index 000000000..754c76bbe --- /dev/null +++ b/app/src/statusbar.h @@ -0,0 +1,99 @@ +/* + +Pencil2D - Traditional Animation Software +Copyright (C) 2020 Jakob Gahde + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +*/ + +#ifndef STATUSBAR_H +#define STATUSBAR_H + +#include + +#include "pencildef.h" + +class Editor; +class ElidedLabel; +class QComboBox; +class QLabel; +class QSlider; + +/** + * The status bar of Pencil2D's main window. + */ +class StatusBar : public QStatusBar +{ + Q_OBJECT + +public: + /** + * Constructs a new status bar. For the status bar to work properly, you must also use setEditor() to pass an Editor instance to it. + * + * @param parent The parent object of the status bar + */ + explicit StatusBar(QWidget *parent = nullptr); + + /** + * Associates an Editor instance with the status bar. + * + * This is necessary for most functionality to work. + * + * @param editor + */ + void setEditor(Editor *editor) { mEditor = editor; } + +public slots: + /** + * Updates the status bar with information about the current tool. + * + * @param tool The currently active tool + */ + void updateToolStatus(ToolType tool); + + /** + * Updates the file modification status. + * + * @param modified Whether the current file contains unsaved modifications + */ + void updateModifiedStatus(bool modified); + + /** + * Updates the zoom level displayed in the status bar. + */ + void updateZoomStatus(); + +signals: + + /** + * This signal is sent when the user chooses a new zoom level through the status bar. + * + * @param scale The new zoom level selected by the user, represented as a scale factor + */ + void zoomChanged(double scale); + +private: + /** The editor associated with this status bar */ + Editor *mEditor = nullptr; + + /** Label used to display the icon of the current tool */ + QLabel *mToolIcon = nullptr; + /** Label used to display a short help text for the current tool */ + ElidedLabel *mToolLabel = nullptr; + /** Label indicating that the current file contains unsaved changes */ + QLabel *mModifiedLabel = nullptr; + /** Combo box for choosing pre-defined or custom zoom levels */ + QComboBox *mZoomBox = nullptr; + /** Slider for adjusting the zoom level */ + QSlider *mZoomSlider = nullptr; +}; + +#endif // STATUSBAR_H diff --git a/app/ui/mainwindow2.ui b/app/ui/mainwindow2.ui index 2a5929f53..86ac656e0 100644 --- a/app/ui/mainwindow2.ui +++ b/app/ui/mainwindow2.ui @@ -42,8 +42,8 @@ - - + + 0 @@ -94,7 +94,6 @@ - @@ -173,12 +172,11 @@ - - - + + @@ -1123,6 +1121,17 @@ Reset Rotation + + + true + + + true + + + Status Bar + + @@ -1137,6 +1146,11 @@
scribblearea.h
1
+ + StatusBar + QStatusBar +
statusbar.h
+
diff --git a/core_lib/data/resources/kb.ini b/core_lib/data/resources/kb.ini index d121e1cdb..32af52ff4 100644 --- a/core_lib/data/resources/kb.ini +++ b/core_lib/data/resources/kb.ini @@ -42,6 +42,7 @@ CmdPreview=Alt+P CmdGrid=G CmdOnionSkinPrevious=O CmdOnionSkinNext=Alt+O +CmdToggleStatusBar= CmdPlay=Ctrl+Return CmdLoop=Ctrl+L CmdFlipInBetween=Alt+Z diff --git a/core_lib/src/managers/preferencemanager.cpp b/core_lib/src/managers/preferencemanager.cpp index 35afefcf3..d8403e983 100644 --- a/core_lib/src/managers/preferencemanager.cpp +++ b/core_lib/src/managers/preferencemanager.cpp @@ -81,6 +81,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()); @@ -350,6 +351,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; diff --git a/core_lib/src/managers/preferencemanager.h b/core_lib/src/managers/preferencemanager.h index 6d4fb23d1..aa049130c 100644 --- a/core_lib/src/managers/preferencemanager.h +++ b/core_lib/src/managers/preferencemanager.h @@ -39,6 +39,7 @@ enum class SETTING DOTTED_CURSOR, HIGH_RESOLUTION, WINDOW_OPACITY, + SHOW_STATUS_BAR, CURVE_SMOOTHING, BACKGROUND_STYLE, AUTO_SAVE, diff --git a/core_lib/src/tool/basetool.h b/core_lib/src/tool/basetool.h index 49753bdfc..510548d86 100644 --- a/core_lib/src/tool/basetool.h +++ b/core_lib/src/tool/basetool.h @@ -74,7 +74,7 @@ class BaseTool : public QObject QString typeName() { return TypeName(type()); } void initialize(Editor* editor); - + virtual ToolType type() = 0; virtual void loadSettings() = 0; virtual QCursor cursor(); @@ -146,6 +146,9 @@ class BaseTool : public QObject bool isPropertyEnabled(ToolPropertyType t) { return mPropertyEnabled[t]; } bool isDrawingTool(); +signals: + bool isActiveChanged(ToolType, bool); + protected: StrokeManager* strokeManager() { return mStrokeManager; } Editor* editor() { return mEditor; } diff --git a/core_lib/src/tool/polylinetool.cpp b/core_lib/src/tool/polylinetool.cpp index 6dd6f04cc..724f1888b 100644 --- a/core_lib/src/tool/polylinetool.cpp +++ b/core_lib/src/tool/polylinetool.cpp @@ -104,6 +104,7 @@ QCursor PolylineTool::cursor() void PolylineTool::clearToolData() { mPoints.clear(); + emit isActiveChanged(POLYLINE, false); } void PolylineTool::pointerPressEvent(PointerEvent* event) @@ -127,6 +128,7 @@ void PolylineTool::pointerPressEvent(PointerEvent* event) } } mPoints << getCurrentPoint(); + emit isActiveChanged(POLYLINE, true); } } } diff --git a/core_lib/src/util/pencildef.h b/core_lib/src/util/pencildef.h index 8b744d3ce..aa4539d6f 100644 --- a/core_lib/src/util/pencildef.h +++ b/core_lib/src/util/pencildef.h @@ -153,6 +153,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" @@ -216,6 +217,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"