Skip to content

Commit

Permalink
Canvas Toolbar: show/hide labels (UI/UX)
Browse files Browse the repository at this point in the history
  • Loading branch information
rodlie committed Jan 12, 2025
1 parent aa65f78 commit 9d56d0c
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/app/GUI/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,8 @@ MainWindow::MainWindow(Document& document,
addToolBar(mColorToolBar);

mCanvasToolBar->addSeparator();
mCanvasToolBar->addAction(new QAction(QIcon::fromTheme("workspace"),
tr("Layout"), this));
mCanvasToolBar->addAction(QIcon::fromTheme("workspace"),
tr("Layout"));
const auto workspaceLayoutCombo = mLayoutHandler->comboWidget();
workspaceLayoutCombo->setMaximumWidth(150);
mCanvasToolBar->addWidget(workspaceLayoutCombo);
Expand Down
56 changes: 46 additions & 10 deletions src/ui/widgets/canvastoolbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ CanvasToolBar::CanvasToolBar(QWidget *parent)
, mSpinWidth(nullptr)
, mSpinHeight(nullptr)
, mComboResolution(nullptr)
, mIconsOnly(AppSupport::getSettings("ui",
"CanvasToolbarIconsOnly",
false).toBool())
{
eSizesUI::widget.add(this, [this](const int size) {
this->setIconSize({size, size});
Expand All @@ -45,7 +48,14 @@ CanvasToolBar::CanvasToolBar(QWidget *parent)
setEnabled(false);
setWindowTitle(tr("Canvas Toolbar"));
setObjectName("CanvasToolBar");
setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
setToolButtonStyle(mIconsOnly ?
Qt::ToolButtonIconOnly :
Qt::ToolButtonTextBesideIcon);

setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, &QWidget::customContextMenuRequested,
this, &CanvasToolBar::showContextMenu);

#ifdef Q_OS_MAC
setStyleSheet(QString("font-size: %1pt;").arg(font().pointSize()));
#endif
Expand Down Expand Up @@ -110,13 +120,13 @@ void CanvasToolBar::setupDimensions()
mSpinHeight->setMaximum(99999);
mSpinHeight->setKeyboardTracking(false);

addAction(new QAction(QIcon::fromTheme("width"),
tr("Width"), this));
addAction(QIcon::fromTheme("width"),
tr("Width"));
addWidget(mSpinWidth);

//addSeparator();
addAction(new QAction(QIcon::fromTheme("height"),
tr("Height"), this));
addAction(QIcon::fromTheme("height"),
tr("Height"));

addWidget(mSpinHeight);
}

Expand All @@ -132,12 +142,10 @@ void CanvasToolBar::setupResolution()
mComboResolution->lineEdit()->setInputMask("D00 %");
mComboResolution->setCurrentText("100 %");
mComboResolution->setInsertPolicy(QComboBox::NoInsert);
//mComboResolution->setSizePolicy(QSizePolicy::Preferred,
// QSizePolicy::Preferred);

addSeparator();
addAction(new QAction(QIcon::fromTheme("resolution"),
tr("Resolution"), this));
addAction(QIcon::fromTheme("resolution"),
tr("Resolution"));

addWidget(mComboResolution);
}
Expand Down Expand Up @@ -198,3 +206,31 @@ void CanvasToolBar::setDimension(const QSize dim,
dim.height());
Document::sInstance->actionFinished();
}

void CanvasToolBar::showContextMenu(const QPoint &pos)
{
QMenu menu(this);
{
const auto act = menu.addAction(QIcon::fromTheme("window"),
windowTitle());
act->setEnabled(false);
menu.addSeparator();
}
{
const auto act = menu.addAction(tr("Labels"));
act->setCheckable(true);
act->setChecked(!mIconsOnly);
connect(act, &QAction::triggered,
this, [this](bool checked) {
mIconsOnly = !checked;
setToolButtonStyle(mIconsOnly ?
Qt::ToolButtonIconOnly :
Qt::ToolButtonTextBesideIcon);
update();
AppSupport::setSettings("ui",
"CanvasToolbarIconsOnly",
mIconsOnly);
});
}
menu.exec(mapToGlobal(pos));
}
4 changes: 2 additions & 2 deletions src/ui/widgets/canvastoolbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ namespace Friction
{
public:
explicit CanvasToolBar(QWidget *parent = nullptr);

void setCurrentCanvas(Canvas * const target);

QComboBox* getResolutionComboBox();

private:
Expand All @@ -57,12 +55,14 @@ namespace Friction
Canvas * const target);
void setDimension(const QSize dim,
Canvas * const target);
void showContextMenu(const QPoint &pos);

QSpinBox *mSpinWidth;
QSpinBox *mSpinHeight;
QComboBox *mComboResolution;

ConnContextQPtr<Canvas> mCanvas;
bool mIconsOnly;
};
}
}
Expand Down

0 comments on commit 9d56d0c

Please sign in to comment.