Skip to content

Commit 3a0d6f5

Browse files
committed
ToolBar: show text besides icons
1 parent 1093b32 commit 3a0d6f5

File tree

3 files changed

+37
-19
lines changed

3 files changed

+37
-19
lines changed

src/unitedentry/unitedentry.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,18 @@ void UnitedEntry::setupUI()
9090
hide();
9191
}
9292

93+
QString UnitedEntry::getTriggerActionText() const
94+
{
95+
return tr("United Entry");
96+
}
97+
9398
QAction *UnitedEntry::getTriggerAction()
9499
{
95100
const auto &themeMgr = VNoteX::getInst().getThemeMgr();
96101
const auto fg = themeMgr.paletteColor("widgets#unitedentry#icon#fg");
97102

98103
const auto icon = IconUtils::fetchIcon(themeMgr.getIconFile("united_entry.svg"), fg);
99-
auto act = new QAction(icon, tr("United Entry"), this);
104+
auto act = new QAction(icon, getTriggerActionText(), this);
100105
connect(act, &QAction::triggered,
101106
this, &UnitedEntry::activateUnitedEntry);
102107

src/unitedentry/unitedentry.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ namespace vnotex
2828

2929
QAction *getTriggerAction();
3030

31+
QString getTriggerActionText() const;
32+
3133
protected:
3234
void showEvent(QShowEvent *p_event) Q_DECL_OVERRIDE;
3335

src/widgets/toolbarhelper.cpp

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,17 @@ QToolBar *ToolBarHelper::setupFileToolBar(MainWindow *p_win, QToolBar *p_toolBar
118118
newBtn->setMenu(newMenu);
119119

120120
// New note.
121+
const auto text = MainWindow::tr("New Note");
121122
auto newNoteAct = newMenu->addAction(generateIcon("new_note.svg"),
122-
MainWindow::tr("New Note"),
123-
newMenu,
123+
text, newMenu,
124124
[]() {
125125
emit VNoteX::getInst().newNoteRequested();
126126
});
127127
WidgetUtils::addActionShortcut(newNoteAct,
128128
coreConfig.getShortcut(CoreConfig::Shortcut::NewNote));
129129
newBtn->setDefaultAction(newNoteAct);
130130
// To hide the shortcut text shown in button.
131-
newBtn->setText(MainWindow::tr("New Note"));
131+
newBtn->setText(text);
132132

133133
// New quick note.
134134
auto newQuickNoteAct = newMenu->addAction(generateIcon("new_note.svg"),
@@ -174,11 +174,12 @@ QToolBar *ToolBarHelper::setupFileToolBar(MainWindow *p_win, QToolBar *p_toolBar
174174
tb->addWidget(newBtn);
175175
}
176176

177-
// Import.
177+
// Import/Export.
178178
{
179-
auto act = tb->addAction(generateIcon("import_menu.svg"), MainWindow::tr("Import"));
179+
auto act = tb->addAction(generateIcon("import_menu.svg"), MainWindow::tr("Import/Export"));
180180

181181
auto btn = dynamic_cast<QToolButton *>(tb->widgetForAction(act));
182+
btn->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
182183
btn->setPopupMode(QToolButton::InstantPopup);
183184
btn->setProperty(PropertyDefs::c_toolButtonWithoutMenuIndicator, true);
184185

@@ -198,16 +199,14 @@ QToolBar *ToolBarHelper::setupFileToolBar(MainWindow *p_win, QToolBar *p_toolBar
198199
[]() {
199200
emit VNoteX::getInst().importFolderRequested();
200201
});
201-
}
202202

203-
// Export.
204-
{
205-
auto exportAct = tb->addAction(generateIcon("export_menu.svg"),
206-
MainWindow::tr("Export (Convert Format)"),
207-
[]() {
208-
emit VNoteX::getInst().exportRequested();
209-
});
203+
newMenu->addSeparator();
210204

205+
auto exportAct = newMenu->addAction(generateIcon("export_menu.svg"),
206+
MainWindow::tr("Export (Convert Format)"),
207+
[]() {
208+
emit VNoteX::getInst().exportRequested();
209+
});
211210
WidgetUtils::addActionShortcut(exportAct,
212211
coreConfig.getShortcut(CoreConfig::Shortcut::Export));
213212
}
@@ -226,9 +225,9 @@ QToolBar *ToolBarHelper::setupQuickAccessToolBar(MainWindow *p_win, QToolBar *p_
226225

227226
// Flash Page.
228227
{
228+
const auto text = MainWindow::tr("Flash Page");
229229
auto flashPageAct = tb->addAction(generateIcon("flash_page_menu.svg"),
230-
MainWindow::tr("Flash Page"),
231-
tb,
230+
text, tb,
232231
[p_win]() {
233232
const auto &flashPage = ConfigMgr::getInst().getSessionConfig().getFlashPage();
234233
if (flashPage.isEmpty()) {
@@ -245,19 +244,25 @@ QToolBar *ToolBarHelper::setupQuickAccessToolBar(MainWindow *p_win, QToolBar *p_
245244
paras->m_mode = ViewWindowMode::Edit;
246245
emit VNoteX::getInst().openFileRequested(flashPage, paras);
247246
});
247+
auto toolBtn = dynamic_cast<QToolButton *>(tb->widgetForAction(flashPageAct));
248+
toolBtn->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
248249
WidgetUtils::addActionShortcut(flashPageAct,
249250
coreConfig.getShortcut(CoreConfig::Shortcut::FlashPage));
251+
// To hide the shortcut text shown in button.
252+
toolBtn->setText(text);
250253
}
251254

252255
// Quick Access.
253256
{
254257
auto toolBtn = WidgetsFactory::createToolButton(tb);
258+
toolBtn->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
255259

256260
auto btnMenu = WidgetsFactory::createMenu(tb);
257261
toolBtn->setMenu(btnMenu);
258262

259263
// Quick Acces.
260-
auto quickAccessAct = btnMenu->addAction(generateIcon("quick_access_menu.svg"), MainWindow::tr("Quick Access"));
264+
const auto text = MainWindow::tr("Quick Access");
265+
auto quickAccessAct = btnMenu->addAction(generateIcon("quick_access_menu.svg"), text);
261266
MainWindow::connect(quickAccessAct, &QAction::triggered,
262267
p_win, [p_win]() {
263268
const auto &quickAccess = ConfigMgr::getInst().getSessionConfig().getQuickAccessFiles();
@@ -275,8 +280,9 @@ QToolBar *ToolBarHelper::setupQuickAccessToolBar(MainWindow *p_win, QToolBar *p_
275280
});
276281
WidgetUtils::addActionShortcut(quickAccessAct,
277282
coreConfig.getShortcut(CoreConfig::Shortcut::QuickAccess));
278-
279283
toolBtn->setDefaultAction(quickAccessAct);
284+
// To hide the shortcut text shown in button.
285+
toolBtn->setText(text);
280286

281287
MainWindow::connect(btnMenu, &QMenu::aboutToShow,
282288
btnMenu, [btnMenu]() {
@@ -294,6 +300,7 @@ QToolBar *ToolBarHelper::setupQuickAccessToolBar(MainWindow *p_win, QToolBar *p_
294300
auto act = tb->addAction(generateIcon("task_menu.svg"), MainWindow::tr("Task"));
295301
auto btn = dynamic_cast<QToolButton *>(tb->widgetForAction(act));
296302
btn->setPopupMode(QToolButton::InstantPopup);
303+
btn->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
297304
btn->setProperty(PropertyDefs::c_toolButtonWithoutMenuIndicator, true);
298305

299306
auto taskMenu = WidgetsFactory::createMenu(tb);
@@ -316,7 +323,11 @@ QToolBar *ToolBarHelper::setupQuickAccessToolBar(MainWindow *p_win, QToolBar *p_
316323
{
317324
// Managed by QObject.
318325
auto ue = new UnitedEntry(p_win);
319-
tb->addAction(ue->getTriggerAction());
326+
auto act = ue->getTriggerAction();
327+
tb->addAction(act);
328+
auto btn = dynamic_cast<QToolButton *>(tb->widgetForAction(act));
329+
btn->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
330+
btn->setText(ue->getTriggerActionText());
320331
}
321332

322333
return tb;

0 commit comments

Comments
 (0)