Pencil2D Animation
Download Community News Docs Contribute
  • Overview
  • Articles
  • Code
  •  
  • Class List
  • Class Index
  • Class Hierarchy
  • Class Members
  • File List
Loading...
Searching...
No Matches
  • app
  • src
statusbar.cpp
1/*
2
3Pencil2D - Traditional Animation Software
4Copyright (C) 2020 Jakob Gahde
5
6This program is free software; you can redistribute it and/or
7modify it under the terms of the GNU General Public License
8as published by the Free Software Foundation; version 2 of the License.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15*/
16
17#include <cmath>
18#include <QComboBox>
19#include <QLabel>
20#include <QLineEdit>
21
22#include "editor.h"
23#include "elidedlabel.h"
24#include "layermanager.h"
25#include "scribblearea.h"
26#include "toolmanager.h"
27#include "viewmanager.h"
28
29#include "statusbar.h"
30
31StatusBar::StatusBar(QWidget *parent) : QStatusBar(parent)
32{
33 setContentsMargins(3, 0, 3, 0);
34
35 mToolIcon = new QLabel(this);
36 addWidget(mToolIcon);
37 mToolLabel = new ElidedLabel(this);
38 mToolLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
39 addWidget(mToolLabel, 1);
40
41 mModifiedLabel = new QLabel(this);
42 mModifiedLabel->setPixmap(QPixmap(":/icons/themes/playful/menubar/save.svg"));
43 updateModifiedStatus(false);
44 addPermanentWidget(mModifiedLabel);
45
46 QLocale locale;
47 mZoomBox = new QComboBox(this);
48 mZoomBox->addItems(QStringList()
49 << locale.toString(10000., 'f', 1) + locale.percent()
50 << locale.toString(6400., 'f', 1) + locale.percent()
51 << locale.toString(1600., 'f', 1) + locale.percent()
52 << locale.toString(800., 'f', 1) + locale.percent()
53 << locale.toString(400., 'f', 1) + locale.percent()
54 << locale.toString(200., 'f', 1) + locale.percent()
55 << locale.toString(100., 'f', 1) + locale.percent()
56 << locale.toString(75., 'f', 1) + locale.percent()
57 << locale.toString(50., 'f', 1) + locale.percent()
58 << locale.toString(33., 'f', 1) + locale.percent()
59 << locale.toString(25., 'f', 1) + locale.percent()
60 << locale.toString(12., 'f', 1) + locale.percent()
61 << locale.toString(1., 'f', 1) + locale.percent());
62 mZoomBox->setMaxCount(mZoomBox->count() + 1);
63 mZoomBox->setEditable(true);
64 mZoomBox->lineEdit()->setAlignment(Qt::AlignRight);
65#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
66 connect(mZoomBox, &QComboBox::textActivated, [=](const QString &currentText)
67#else
68 connect(mZoomBox, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::activated), [=](const QString &currentText)
69#endif
70 {
71 if (mZoomBox->count() == mZoomBox->maxCount())
72 {
73 // Keep the size of the list reasonable by preventing user entries
74 // insertPolicy is unsuitable as it prevents entering custom values at all
75 mZoomBox->removeItem(mZoomBox->maxCount() - 1);
76 }
77 emit zoomChanged(locale.toDouble(QString(currentText).remove(locale.percent())) / 100);
78 });
79 addPermanentWidget(mZoomBox);
80
81 mZoomSlider = new QSlider(Qt::Horizontal, this);
82 mZoomSlider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
83 mZoomSlider->setRange(-20, 20);
84 mZoomSlider->setTickPosition(QSlider::TicksBelow);
85 mZoomSlider->setTickInterval(20);
86 connect(mZoomSlider, &QSlider::valueChanged, [this](int value)
87 {
88 emit zoomChanged(std::pow(10, value / 10.));
89 });
90 addPermanentWidget(mZoomSlider);
91}
92
93void StatusBar::updateToolStatus(ToolType tool)
94{
95 Q_ASSERT(mEditor);
96 switch (tool) {
97 case PENCIL:
98 mToolLabel->setText(tr("Click to draw. Hold Ctrl and Shift to erase or Alt to select a color from the canvas."));
99 break;
100 case ERASER:
101 mToolLabel->setText(tr("Click to erase."));
102 break;
103 case SELECT:
104 mToolLabel->setText(tr("Click and drag to create or modify a selection. Hold Alt to modify its contents or press Backspace to clear them."));
105 break;
106 case MOVE:
107 mToolLabel->setText(tr("Click and drag to move an object. Hold Ctrl to rotate."));
108 break;
109 case CAMERA:
110 mToolLabel->setText(tr("Click and drag to move the camera. While on in-between frames, drag handle to change interpolation."));
111 break;
112 case HAND:
113 mToolLabel->setText(tr("Click and drag to pan. Hold Ctrl to zoom or Alt to rotate."));
114 break;
115 case SMUDGE:
116 mToolLabel->setText(tr("Click to liquefy pixels or modify a vector line. Hold Alt to smooth."));
117 break;
118 case PEN:
119 mToolLabel->setText(tr("Click to draw. Hold Ctrl and Shift to erase or Alt to select a color from the canvas."));
120 break;
121 case POLYLINE:
122 if (mEditor->tools()->getTool(tool)->isActive())
123 {
124 mToolLabel->setText(tr("Click to continue the polyline. Double-click or press enter to complete the line or press Escape to discard it."));
125 }
126 else
127 {
128 mToolLabel->setText(tr("Click to create a new polyline. Hold Ctrl and Shift to erase."));
129 }
130 break;
131 case BUCKET:
132 mToolLabel->setText(tr("Click to fill an area with the current color. Hold Alt to select a color from the canvas."));
133 break;
134 case EYEDROPPER:
135 mToolLabel->setText(tr("Click to select a color from the canvas."));
136 break;
137 case BRUSH:
138 mToolLabel->setText(tr("Click to paint. Hold Ctrl and Shift to erase or Alt to select a color from the canvas."));
139 break;
140 default:
141 Q_ASSERT(false);
142 }
143
144 static QPixmap toolIcons[TOOL_TYPE_COUNT]{
145 {":icons/themes/playful/tools/tool-pencil.svg"},
146 {":icons/themes/playful/tools/tool-eraser.svg"},
147 {":icons/themes/playful/tools/tool-select.svg"},
148 {":icons/themes/playful/tools/tool-move.svg"},
149 {":icons/themes/playful/tools/tool-hand.svg"},
150 {":icons/themes/playful/tools/tool-smudge.svg"},
151 {""}, // Camera tool does not have an icon
152 {":icons/themes/playful/tools/tool-pen.svg"},
153 {":icons/themes/playful/tools/tool-polyline.svg"},
154 {":icons/themes/playful/tools/tool-bucket.svg"},
155 {":icons/themes/playful/tools/tool-eyedropper.svg"},
156 {":icons/themes/playful/tools/tool-brush.svg"}
157 };
158 mToolIcon->setPixmap(toolIcons[tool]);
159 mToolIcon->setToolTip(BaseTool::TypeName(tool));
160}
161
162void StatusBar::updateModifiedStatus(bool modified)
163{
164 mModifiedLabel->setDisabled(!modified);
165 if (modified)
166 {
167 mModifiedLabel->setToolTip(tr("This file has unsaved changes"));
168 }
169 else
170 {
171 mModifiedLabel->setToolTip(tr("This file has no unsaved changes"));
172 }
173}
174
175void StatusBar::updateZoomStatus()
176{
177 Q_ASSERT(mEditor);
178
179 QLocale locale;
180 QSignalBlocker b1(mZoomBox);
181 mZoomBox->setCurrentText(locale.toString(mEditor->view()->scaling() * 100, 'f', 1) + locale.percent());
182
183 QSignalBlocker b2(mZoomSlider);
184 mZoomSlider->setValue(static_cast<int>(std::round(std::log10(mEditor->view()->scaling()) * 10)));
185}
BaseTool::isActive
virtual bool isActive() const
Check if the tool is active.
Definition: basetool.cpp:125
ElidedLabel
[0]
Definition: elidedlabel.h:59
ElidedLabel::setText
void setText(const QString &text)
[0]
Definition: elidedlabel.cpp:74
StatusBar::StatusBar
StatusBar(QWidget *parent=nullptr)
Constructs a new status bar.
Definition: statusbar.cpp:31
StatusBar::mToolLabel
ElidedLabel * mToolLabel
Label used to display a short help text for the current tool.
Definition: statusbar.h:90
StatusBar::updateModifiedStatus
void updateModifiedStatus(bool modified)
Updates the file modification status.
Definition: statusbar.cpp:162
StatusBar::mZoomBox
QComboBox * mZoomBox
Combo box for choosing pre-defined or custom zoom levels.
Definition: statusbar.h:94
StatusBar::mToolIcon
QLabel * mToolIcon
Label used to display the icon of the current tool.
Definition: statusbar.h:88
StatusBar::updateToolStatus
void updateToolStatus(ToolType tool)
Updates the status bar with information about the current tool.
Definition: statusbar.cpp:93
StatusBar::mEditor
Editor * mEditor
The editor associated with this status bar.
Definition: statusbar.h:85
StatusBar::zoomChanged
void zoomChanged(double scale)
This signal is sent when the user chooses a new zoom level through the status bar.
StatusBar::mModifiedLabel
QLabel * mModifiedLabel
Label indicating that the current file contains unsaved changes.
Definition: statusbar.h:92
StatusBar::mZoomSlider
QSlider * mZoomSlider
Slider for adjusting the zoom level.
Definition: statusbar.h:96
StatusBar::updateZoomStatus
void updateZoomStatus()
Updates the zoom level displayed in the status bar.
Definition: statusbar.cpp:175
QAbstractSlider::setRange
void setRange(int min, int max)
QAbstractSlider::setValue
void setValue(int)
QAbstractSlider::valueChanged
void valueChanged(int value)
QComboBox
QComboBox::activated
void activated(int index)
QComboBox::addItems
void addItems(const QStringList &texts)
QComboBox::count
count
QComboBox::setCurrentText
void setCurrentText(const QString &text)
QComboBox::setEditable
void setEditable(bool editable)
QComboBox::lineEdit
QLineEdit * lineEdit() const const
QComboBox::setMaxCount
void setMaxCount(int max)
QComboBox::textActivated
void textActivated(const QString &text)
QLabel
QLabel::setPixmap
void setPixmap(const QPixmap &)
QLineEdit::setAlignment
void setAlignment(Qt::Alignment flag)
QLocale
QObject::connect
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject::tr
QString tr(const char *sourceText, const char *disambiguation, int n)
QPixmap
QSignalBlocker
QSizePolicy::Expanding
Expanding
QSlider
QSlider::TicksBelow
TicksBelow
QSlider::setTickInterval
void setTickInterval(int ti)
QSlider::setTickPosition
void setTickPosition(QSlider::TickPosition position)
QStatusBar
QStatusBar::addPermanentWidget
void addPermanentWidget(QWidget *widget, int stretch)
QStatusBar::addWidget
void addWidget(QWidget *widget, int stretch)
QString
QStringList
Qt::AlignRight
AlignRight
Qt::Horizontal
Horizontal
QWidget
QWidget::locale
locale
QWidget::setContentsMargins
void setContentsMargins(int left, int top, int right, int bottom)
QWidget::setDisabled
void setDisabled(bool disable)
QWidget::setSizePolicy
void setSizePolicy(QSizePolicy)
QWidget::setToolTip
void setToolTip(const QString &)
Generated on Thu May 8 2025 04:47:53 for Pencil2D by doxygen 1.9.6 based on revision 4513250b1d5b1a3676ec0e67b06b7a885ceaae39