Skip to content

Commit 1f0c96b

Browse files
authored
Merge pull request #89 from yanagiragi/59-add-menubar
feat: Support menubar
2 parents cbdc918 + 9aa7650 commit 1f0c96b

File tree

5 files changed

+153
-0
lines changed

5 files changed

+153
-0
lines changed

cpp/modmesh/view/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ set(MODMESH_VIEW_HEADERS
1010
${CMAKE_CURRENT_SOURCE_DIR}/RMainWindow.hpp
1111
${CMAKE_CURRENT_SOURCE_DIR}/RPythonText.hpp
1212
${CMAKE_CURRENT_SOURCE_DIR}/RStaticMesh.hpp
13+
${CMAKE_CURRENT_SOURCE_DIR}/RMenu.hpp
1314
${CMAKE_CURRENT_SOURCE_DIR}/view.hpp
1415
CACHE FILEPATH "" FORCE
1516
)
@@ -21,6 +22,7 @@ set(MODMESH_VIEW_SOURCES
2122
${CMAKE_CURRENT_SOURCE_DIR}/RMainWindow.cpp
2223
${CMAKE_CURRENT_SOURCE_DIR}/RPythonText.cpp
2324
${CMAKE_CURRENT_SOURCE_DIR}/RStaticMesh.cpp
25+
${CMAKE_CURRENT_SOURCE_DIR}/RMenu.cpp
2426
CACHE FILEPATH "" FORCE
2527
)
2628

cpp/modmesh/view/RApplication.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,27 @@ RApplication::RApplication(int & argc, char ** argv)
4343
python::Interpreter::instance().preload_modules({"_modmesh_view", "modmesh"});
4444
pybind11::exec("modmesh.view = _modmesh_view");
4545

46+
RMenuBar * menuBar = new RMenuBar();
47+
RMenu * fileMmenu = new RMenu(QString("File"));
48+
RMenu * newMenu = new RMenu(QString("New"));
49+
RAction * newFileAction = new RAction(
50+
QString("New file"),
51+
QString("Create new file"),
52+
[]()
53+
{
54+
qDebug() << "Create new file!";
55+
});
56+
RAction * exitAction = new RAction(
57+
QString("Exit"),
58+
QString("Exit the application"),
59+
quit);
60+
61+
newMenu->addAction(newFileAction);
62+
fileMmenu->addMenu(newMenu);
63+
fileMmenu->addAction(exitAction);
64+
menuBar->addMenu(fileMmenu);
65+
m_main->setMenuBar(menuBar);
66+
4667
// Show main window.
4768
m_main->show();
4869
}

cpp/modmesh/view/RApplication.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <modmesh/view/common_detail.hpp> // Must be the first include.
3232

3333
#include <modmesh/view/RMainWindow.hpp>
34+
#include <modmesh/view/RMenu.hpp>
3435

3536
#include <Qt>
3637
#include <QApplication>

cpp/modmesh/view/RMenu.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright (c) 2022, Yung-Yu Chen <[email protected]>
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions are met:
6+
*
7+
* - Redistributions of source code must retain the above copyright notice,
8+
* this list of conditions and the following disclaimer.
9+
* - Redistributions in binary form must reproduce the above copyright notice,
10+
* this list of conditions and the following disclaimer in the documentation
11+
* and/or other materials provided with the distribution.
12+
* - Neither the name of the copyright holder nor the names of its contributors
13+
* may be used to endorse or promote products derived from this software
14+
* without specific prior written permission.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
* POSSIBILITY OF SUCH DAMAGE.
27+
*/
28+
29+
#include <modmesh/view/RMenu.hpp> // Must be the first include.
30+
31+
namespace modmesh
32+
{
33+
34+
RAction::RAction(QString const & text, QString const & tipText, std::function<void(void)> callback, QObject * parent)
35+
: QAction(text, parent)
36+
{
37+
setStatusTip(tipText);
38+
if (callback != nullptr)
39+
{
40+
connect(this, &QAction::triggered, this, callback);
41+
}
42+
}
43+
44+
RMenu::RMenu(QString const & text, QWidget * parent)
45+
: QMenu(text, parent)
46+
{
47+
}
48+
49+
RMenuBar::RMenuBar(QWidget * parent)
50+
: QMenuBar(parent)
51+
{
52+
}
53+
54+
} /* end namespace modmesh */
55+
56+
// vim: set ff=unix fenc=utf8 et sw=4 ts=4 sts=4:

cpp/modmesh/view/RMenu.hpp

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#pragma once
2+
3+
/*
4+
* Copyright (c) 2022, Yung-Yu Chen <[email protected]>
5+
*
6+
* Redistribution and use in source and binary forms, with or without
7+
* modification, are permitted provided that the following conditions are met:
8+
*
9+
* - Redistributions of source code must retain the above copyright notice,
10+
* this list of conditions and the following disclaimer.
11+
* - Redistributions in binary form must reproduce the above copyright notice,
12+
* this list of conditions and the following disclaimer in the documentation
13+
* and/or other materials provided with the distribution.
14+
* - Neither the name of the copyright holder nor the names of its contributors
15+
* may be used to endorse or promote products derived from this software
16+
* without specific prior written permission.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
* A*RE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+
* POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
31+
#include <modmesh/view/common_detail.hpp> // Must be the first include.
32+
33+
#include <Qt>
34+
#include <QMenu>
35+
#include <QMenuBar>
36+
#include <QAction>
37+
38+
#include <functional>
39+
40+
namespace modmesh
41+
{
42+
43+
class RMenuBar
44+
: public QMenuBar
45+
{
46+
public:
47+
RMenuBar(
48+
QWidget * parent = nullptr);
49+
}; /* end class RMenuBar */
50+
51+
class RAction
52+
: public QAction
53+
{
54+
public:
55+
RAction(
56+
QString const & text,
57+
QString const & tipText,
58+
std::function<void(void)> callback,
59+
QObject * parent = nullptr);
60+
}; /* end class RAction */
61+
62+
class RMenu
63+
: public QMenu
64+
{
65+
public:
66+
RMenu(
67+
QString const & text,
68+
QWidget * parent = nullptr);
69+
}; /* end class RMenu */
70+
71+
} /* end namespace modmesh */
72+
73+
// vim: set ff=unix fenc=utf8 et sw=4 ts=4 sts=4:

0 commit comments

Comments
 (0)