Commit 0e80b485 authored by jean lima andrade's avatar jean lima andrade
Browse files

Use XXmlGuiWindow instead of QMainWindow

parent ae9d1f70
......@@ -13,6 +13,27 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
find_package(ECM 1.0.0 REQUIRED NO_MODULE)
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
include(KDEInstallDirs)
include(KDECMakeSettings)
#include(KDECompilerSettings)
include(FeatureSummary)
find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS
Core # QStringLiteral
Widgets # QApplication, QAction
)
find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS
CoreAddons # KAboutData
XmlGui # KXmlGuiWindow, KActionCollection
ConfigWidgets # KStandardActions
)
feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES)
include(ui/CMakeLists.txt)
include(util/CMakeLists.txt)
include(text/CMakeLists.txt)
......@@ -30,6 +51,12 @@ set(mark_SRC
add_executable(mark ${mark_SRC})
target_link_libraries(mark Qt5::Widgets)
target_link_libraries(mark
Qt5::Core
Qt5::Widgets
KF5::CoreAddons
KF5::XmlGui
)
install(TARGETS mark DESTINATION bin)
install(TARGETS mark ${INSTALL_TARGETS_DEFAULT_ARGS})
install(FILES ui/markui.rc DESTINATION ${KXMLGUI_INSTALL_DIR}/mark)
......@@ -19,10 +19,40 @@
#include <QApplication>
#include <QScreen>
#include <KAboutData>
#include <KXmlGuiWindow>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
KAboutData aboutData(
// The program name used internally. (componentName)
QStringLiteral("mark"),
// A displayable program name string. (displayName)
QStringLiteral("marK"),
// The program version string. (version)
QStringLiteral("0.0.1"),
// Short description of what the app does. (shortDescription)
QStringLiteral("A dataset annotation tool meant to help in the process of annotating data."),
// The license this code is released under
KAboutLicense::GPL_V3,
// Copyright Statement (copyrightStatement = QString())
QStringLiteral("(c) 2020"),
// Optional text shown in the About box.
// Can contain any information desired. (otherText)
QStringLiteral("The project is in its early stage of development, currently supports image and text annotation."),
// The program homepage string. (homePageAddress = QString())
QStringLiteral("https://invent.kde.org/education/mark"),
// The bug report email address
// (bugsEmailAddress = QLatin1String("submit@bugs.kde.org")
QStringLiteral("submit@bugs.kde.org"));
aboutData.addAuthor(QStringLiteral("Caio Jordão Carvalho"), QStringLiteral("Mantainer"), QStringLiteral("caiojcarvalho@gmail.com"),
QStringLiteral("caiojcarvalho.wordpress.com"), QStringLiteral("cjlcarvalho"));
aboutData.addAuthor(QStringLiteral("Jean Lima Andrade"), QStringLiteral("Contribuitor"), QStringLiteral("jyeno@protonmail.com"),
QStringLiteral("jyeno.home.blog"), QStringLiteral("jyeno"));
KAboutData::setApplicationData(aboutData);
marK w;
w.setFixedSize(qApp->primaryScreen()->availableSize());
w.setWindowState(Qt::WindowMaximized);
......@@ -31,4 +61,3 @@ int main(int argc, char *argv[])
return app.exec();
}
......@@ -37,6 +37,7 @@
#include <QMessageBox>
#include <QShortcut>
#include <KActionCollection>
static QDir markDirectory()
{
......@@ -44,7 +45,7 @@ static QDir markDirectory()
}
marK::marK(QWidget *parent) :
QMainWindow(parent),
KXmlGuiWindow(parent),
m_ui(new Ui::marK),
m_watcher(new QFileSystemWatcher(this)),
m_currentDirectory(QDir::currentPath()),
......@@ -54,9 +55,11 @@ marK::marK(QWidget *parent) :
m_ui->setupUi(this);
m_ui->listLabel->setText(m_currentDirectory);
m_ui->listLabel->setToolTip(m_currentDirectory);
m_ui->containerWidget->setMinimumSize(860, 650);
setupActions();
setupConnections();
setupGUI(Default);
updateFiles();
addNewClass();
......@@ -67,54 +70,64 @@ marK::marK(QWidget *parent) :
void marK::setupActions()
{
QMenu *fileMenu = m_ui->menuBar->addMenu("File");
QAction *openDirAction = fileMenu->addAction("Open Directory");
openDirAction->setShortcut(QKeySequence(Qt::Modifier::CTRL + Qt::Key::Key_O));
QAction *openDirAction = new QAction(this);
openDirAction->setText("Open Directory");
openDirAction->setIcon(QIcon::fromTheme("document-open"));
actionCollection()->setDefaultShortcut(openDirAction, Qt::Modifier::CTRL + Qt::Key::Key_O);
actionCollection()->addAction("openDirectory", openDirAction);
connect(openDirAction, &QAction::triggered, this, &marK::changeDirectory);
QAction *importData = fileMenu->addAction("Import");
importData->setShortcut(QKeySequence(Qt::Modifier::CTRL + Qt::Key::Key_I));
QAction *importData = new QAction(this);
importData->setText("Import");
actionCollection()->setDefaultShortcut(importData, Qt::Modifier::CTRL + Qt::Key::Key_I);
actionCollection()->addAction("importData", importData);
connect(importData, &QAction::triggered, this, &marK::importData);
QMenu *exportMenu = fileMenu->addMenu("Export");
QAction *toXML = exportMenu->addAction("XML");
QAction *toXML = new QAction(this);
toXML->setText("XML");
actionCollection()->addAction("toXML", toXML);
connect(toXML, &QAction::triggered, [&](){ saveObjects(Serializer::OutputType::XML); });
QAction *toJson = exportMenu->addAction("JSON");
QAction *toJson = new QAction(this);
toJson->setText("JSON");
actionCollection()->addAction("toJSON", toJson);
connect(toJson, &QAction::triggered, [&](){ saveObjects(Serializer::OutputType::JSON); });
QMenu *editMenu = m_ui->menuBar->addMenu("Edit");
QAction *undoAction = editMenu->addAction("Undo");
undoAction->setShortcut(QKeySequence(Qt::Modifier::CTRL + Qt::Key::Key_Z));
QAction *undoAction = new QAction(this);
undoAction->setText("Undo");
actionCollection()->setDefaultShortcut(undoAction, Qt::Modifier::CTRL + Qt::Key::Key_Z);
actionCollection()->addAction("undo", undoAction);
connect(undoAction, &QAction::triggered, m_ui->containerWidget, &Container::undo);
QAction *deleteAction = editMenu->addAction("Delete");
deleteAction->setShortcut(QKeySequence(Qt::Modifier::CTRL + Qt::Key::Key_D));
QAction *deleteAction = new QAction(this);
deleteAction->setText("Delete");
actionCollection()->setDefaultShortcut(deleteAction, Qt::Modifier::CTRL + Qt::Key::Key_D);
actionCollection()->addAction("delete", deleteAction);
connect(deleteAction, &QAction::triggered, m_ui->containerWidget, &Container::deleteObject);
m_ui->containerWidget->setMinimumSize(860, 650);
QMenu *autoSaveMenu = editMenu->addMenu("Auto Save");
QActionGroup *autoSaveActionGroup = new QActionGroup(this);
QAction *autoSaveJsonButton = autoSaveMenu->addAction("JSON");
QAction *autoSaveJsonButton = new QAction(this);
autoSaveJsonButton->setText("JSON");
autoSaveJsonButton->setCheckable(true);
connect(autoSaveJsonButton, &QAction::triggered, this, &marK::toggleAutoSave);
autoSaveJsonButton->setActionGroup(autoSaveActionGroup);
actionCollection()->addAction("autosaveJSON", autoSaveJsonButton);
connect(autoSaveJsonButton, &QAction::triggered, this, &marK::toggleAutoSave);
QAction *autoSaveXmlButton = autoSaveMenu->addAction("XML");
QAction *autoSaveXmlButton = new QAction(this);
autoSaveXmlButton->setText("XML");
autoSaveXmlButton->setCheckable(true);
connect(autoSaveXmlButton, &QAction::triggered, this, &marK::toggleAutoSave);
autoSaveXmlButton->setActionGroup(autoSaveActionGroup);
actionCollection()->addAction("autosaveXML", autoSaveXmlButton);
connect(autoSaveXmlButton, &QAction::triggered, this, &marK::toggleAutoSave);
QAction *autoSaveDisableButton = autoSaveMenu->addAction("Disabled");
autoSaveDisableButton->setCheckable(true);
autoSaveDisableButton->setChecked(true);
connect(autoSaveDisableButton, &QAction::triggered, this, &marK::toggleAutoSave);
autoSaveDisableButton->setActionGroup(autoSaveActionGroup);
QAction *autoSaveDisabledButton = new QAction(this);
autoSaveDisabledButton->setText("Disabled");
autoSaveDisabledButton->setCheckable(true);
autoSaveDisabledButton->setChecked(true);
autoSaveDisabledButton->setActionGroup(autoSaveActionGroup);
actionCollection()->addAction("autosaveDisabled", autoSaveDisabledButton);
connect(autoSaveDisabledButton, &QAction::triggered, this, &marK::toggleAutoSave);
QShortcut *nextItemShortcut = new QShortcut(this);
nextItemShortcut->setKey(Qt::Key_Down);
......@@ -136,6 +149,8 @@ void marK::setupConnections()
m_ui->polygonButton->setEnabled(false);
m_ui->rectButton->setEnabled(false);
KStandardAction::quit(qApp, SLOT(quit()), actionCollection());
connect(m_ui->listWidget, &QListWidget::currentItemChanged, this,
qOverload<QListWidgetItem*, QListWidgetItem*>(&marK::changeItem));
......
......@@ -21,17 +21,18 @@
#include "ui/markedclass.h"
#include "util/serializer.h"
#include <QMainWindow>
#include <QScopedPointer>
#include <QListWidgetItem>
#include <QFileSystemWatcher>
#include <KXmlGuiWindow>
namespace Ui {
class marK;
}
/** Main class, also represents the main window. */
class marK : public QMainWindow
class marK : public KXmlGuiWindow
{
Q_OBJECT
......
<?xml version="1.0" encoding="UTF-8"?>
<gui name="mark"
version="0.0.1"
xmlns="http://www.kde.org/standards/kxmlgui/1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.kde.org/standards/kxmlgui/1.0
http://www.kde.org/standards/kxmlgui/1.0/kxmlgui.xsd" >
<MenuBar>
<Menu name="file" ><text>File</text>
<Action name="openDirectory" />
<Action name="importData" />
<Menu name="exportData" ><text>Save as</text>
<Action name="toJSON" />
<Action name="toXML" />
</Menu>
</Menu>
<Menu name="edit" ><text>Edit</text>
<Action name="undo" />
<Action name="delete" />
<Action name="autosave" />
<Menu name="autosave" ><text>autosave</text>
<Action name="autosaveDisabled" />
<Action name="autosaveJSON" />
<Action name="autosaveXML" />
</Menu>
</Menu>
</MenuBar>
</gui>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment