Skip to content

Commit

Permalink
Gui: Add support for hints in status bar
Browse files Browse the repository at this point in the history
  • Loading branch information
kadet1090 committed Jan 9, 2025
1 parent c420316 commit 136c6ad
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 2 deletions.
17 changes: 17 additions & 0 deletions src/Gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ struct MainWindowP
{
DimensionWidget* sizeLabel;
QLabel* actionLabel;
QLabel* hintLabel;
QLabel* rightSideLabel;
QTimer* actionTimer;
QTimer* statusTimer;
Expand Down Expand Up @@ -391,6 +392,12 @@ MainWindow::MainWindow(QWidget * parent, Qt::WindowFlags f)
statusBar()->addPermanentWidget(progressBar, 0);
statusBar()->addPermanentWidget(d->sizeLabel, 0);


// hint label
d->hintLabel = new QLabel(statusBar());
statusBar()->addWidget(d->hintLabel);

// right side label
d->rightSideLabel = new QLabel(statusBar());
d->rightSideLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
statusBar()->addPermanentWidget(d->rightSideLabel);
Expand Down Expand Up @@ -2221,6 +2228,16 @@ void MainWindow::showStatus(int type, const QString& message)
statusBar()->showMessage(msg.simplified(), timeout);
}

void MainWindow::showHint(const QString& hint)
{
d->hintLabel->setText(hint);
}

void MainWindow::hideHint()
{
d->hintLabel->setText({});
}


// set text to the pane
void MainWindow::setPaneText(int i, QString text)
Expand Down
5 changes: 4 additions & 1 deletion src/Gui/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,10 @@ class GuiExport MainWindow : public QMainWindow
void updateActions(bool delay = false);

enum StatusType {None, Err, Wrn, Pane, Msg, Log, Tmp, Critical};
void showStatus(int type, const QString & message);
void showStatus(int type, const QString& message);

void showHint(const QString& hint);
void hideHint();

void initDockWindows(bool show);

Expand Down
12 changes: 12 additions & 0 deletions src/Gui/ToolHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ bool ToolHandler::activate()
oldCursor = cw->cursor();

updateCursor();
updateHint();

this->preActivated();
this->activated();
Expand All @@ -74,6 +75,8 @@ void ToolHandler::deactivate()
this->postDeactivated();

unsetCursor();

Gui::MainWindow::getInstance()->hideHint();
}

//**************************************************************************
Expand Down Expand Up @@ -234,6 +237,15 @@ void ToolHandler::updateCursor()
setCrosshairCursor(cursorstring);
}
}
QString ToolHandler::getToolHintText() const
{
return QString();
}

void ToolHandler::updateHint() const
{
Gui::getMainWindow()->showHint(getToolHintText());
}

void ToolHandler::applyCursor()
{
Expand Down
3 changes: 3 additions & 0 deletions src/Gui/ToolHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ class GuiExport ToolHandler
/// enabling to set data member dependent icons (i.e. for different construction methods)
void updateCursor();

virtual QString getToolHintText() const;
void updateHint() const;

private: // NVI
virtual void preActivated()
{}
Expand Down
3 changes: 3 additions & 0 deletions src/Mod/Sketcher/Gui/DrawSketchControllableHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,10 @@ class DrawSketchControllableHandler
bool onModeChanged() override
{
DrawSketchHandler::resetPositionText();
DrawSketchHandler::updateHint();

toolWidgetManager.onHandlerModeChanged();

if (DSDefaultHandler::onModeChanged()) {
// If onModeChanged returns false, then the handler has been purged.
toolWidgetManager.afterHandlerModeChanged();
Expand Down
1 change: 0 additions & 1 deletion src/Mod/Sketcher/Gui/DrawSketchHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,6 @@ QString DrawSketchHandler::getToolWidgetText() const
return QString();
}


void DrawSketchHandler::activate(ViewProviderSketch* vp)
{
sketchgui = vp;
Expand Down
6 changes: 6 additions & 0 deletions src/Mod/Sketcher/Gui/DrawSketchHandlerLineSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ class DrawSketchHandlerLineSet: public DrawSketchHandler
SNAP_MODE_45Degree
};

QString getToolHintText() const override
{
return QWidget::tr("Press <b>M</b> to change mode, <b>left click</b> to start drawing "
"and <b>right click</b> to stop drawing");
}

void registerPressedKey(bool pressed, int key) override
{
if (Mode == STATUS_SEEK_Second && key == SoKeyboardEvent::M && pressed
Expand Down
15 changes: 15 additions & 0 deletions src/Mod/Sketcher/Gui/DrawSketchHandlerPolygon.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,21 @@ class DrawSketchHandlerPolygon: public DrawSketchHandlerPolygonBase
{}
~DrawSketchHandlerPolygon() override = default;

QString getToolHintText() const override
{
switch (state()) {
case SelectMode::SeekFirst:
return QWidget::tr("Use <b>left click</b> to pick polygon center, "
"<b>U</b>/<b>J</b> to increase/decrease number of sides");
case SelectMode::SeekSecond:
return QWidget::tr(
"Use mouse to pick rotation and size, <b>left click</b> to confirm, "
"<b>U</b>/<b>J</b> to increase/decrease number of sides");
default:
return {};
}
}

private:
void updateDataAndDrawToPosition(Base::Vector2d onSketchPos) override
{
Expand Down

0 comments on commit 136c6ad

Please sign in to comment.