Skip to content

Commit 2548db7

Browse files
committed
feat: add toolbar and status bar initialization in MainWindow, and implement ToolBar class with actions
1 parent 7b1dc96 commit 2548db7

20 files changed

+378
-2
lines changed

parser/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ file(GLOB Widgets_SRC
4141
"${ROOT_DIR}/Widgets/include/*.h"
4242
)
4343

44-
4544
set(Widgets
4645
MainWindow.cpp MainWindow.h
4746
${Widgets_SRC}
@@ -72,9 +71,11 @@ if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
7271
${Scanner}
7372
${Data}
7473
${FileHandling}
74+
resources.qrc
7575
)
7676
endif()
7777

78+
7879
# Include directories for headers
7980
include_directories(
8081
${ROOT_DIR}/Parser/include

parser/MainWindow.cpp

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,34 @@
22

33
MainWindow::MainWindow(QWidget *parent)
44
: QMainWindow(parent)
5-
{}
5+
{
6+
// set the window title
7+
setWindowTitle("Tiny Parser");
8+
9+
// set the window size
10+
resize(800, 600);
11+
12+
// initialize the toolbar
13+
initToolbar();
14+
15+
// initialize the status bar
16+
initStatusBar();
17+
}
618

719
MainWindow::~MainWindow() {}
20+
21+
void MainWindow::initToolbar()
22+
{
23+
// Create a new toolba
24+
Tiny::Widgets::ToolBar *toolbar = new Tiny::Widgets::ToolBar(this);
25+
this->addToolBar(toolbar);
26+
}
27+
28+
void MainWindow::initStatusBar()
29+
{
30+
// Create a new status bar
31+
QStatusBar *statusBar = new QStatusBar(this);
32+
this->setStatusBar(statusBar);
33+
}
34+
35+

parser/MainWindow.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
#ifndef MAINWINDOW_H
22
#define MAINWINDOW_H
33

4+
#include "ToolBar.h"
5+
46
#include <QMainWindow>
7+
#include <QGuiApplication>
8+
#include <QStyle>
9+
#include <QScreen>
10+
#include <QDebug>
11+
#include <QToolBar>
12+
#include <QStatusBar>
513

614
class MainWindow : public QMainWindow
715
{
@@ -10,5 +18,10 @@ class MainWindow : public QMainWindow
1018
public:
1119
MainWindow(QWidget *parent = nullptr);
1220
~MainWindow();
21+
22+
23+
private:
24+
void initToolbar();
25+
void initStatusBar();
1326
};
1427
#endif // MAINWINDOW_H

parser/Widgets/include/ToolBar.h

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#ifndef TOOLBAR_H
2+
#define TOOLBAR_H
3+
4+
#include <QToolBar>
5+
#include <QAction>
6+
#include <QIcon>
7+
#include <QDebug>
8+
#include <QObject>
9+
#include <QVector>
10+
11+
#include <functional>
12+
13+
namespace Tiny::Widgets {
14+
15+
class ToolBar : public QToolBar
16+
{
17+
Q_OBJECT
18+
public:
19+
enum class ActionName {
20+
NewTextFile,
21+
NewTokensFile,
22+
OpenFile,
23+
SaveFile,
24+
SaveAsFile,
25+
ViewTextFile,
26+
ViewTokens,
27+
ViewParseTree,
28+
ViewSyntaxTree,
29+
Help,
30+
About
31+
};
32+
33+
explicit ToolBar(QWidget *parent = nullptr);
34+
~ToolBar();
35+
36+
37+
QAction* getAction(const QString& name);
38+
void setActionEnabled(const QString& name, bool enabled);
39+
void setActionVisible(const QString& name, bool visible);
40+
41+
private:
42+
QVector<QAction*> actions;
43+
44+
void initFileActions();
45+
void initViewActions();
46+
void initHelpActions();
47+
48+
struct Action {
49+
ActionName name;
50+
QString statusTip;
51+
QKeySequence shortcut;
52+
std::function<void()> slot;
53+
};
54+
void addToolbarAction(Action* action, bool onOffAction = false, bool onByDefault = false);
55+
56+
void initStyle();
57+
58+
// lookup table for action enum to string
59+
static const QMap<ActionName, QString> actionNameToString;
60+
61+
62+
63+
public slots:
64+
65+
signals:
66+
67+
68+
69+
}; // class ToolBar
70+
} // namespace Tiny::Widgets
71+
#endif // TOOLBAR_H

0 commit comments

Comments
 (0)