Commit 90094cb2 authored by WINTZ Julien's avatar WINTZ Julien

Orgasmic commit.

- Adds dtkWidgetsMainWindow
- Enhances dtkApplication
parent 3ce47717
......@@ -100,10 +100,12 @@ find_package(Qt5 REQUIRED COMPONENTS Core WebSockets Widgets Xml Test)
find_package(dtkCore REQUIRED)
find_package(dtkFonts REQUIRED)
find_package(dtkLog REQUIRED)
find_package(dtkThemes REQUIRED)
include_directories(${dtkCore_INCLUDE_DIRS})
include_directories(${dtkFonts_INCLUDE_DIRS})
include_directories(${dtkLog_INCLUDE_DIRS})
include_directories(${dtkThemes_INCLUDE_DIRS})
## #################################################################
## Dependencies - internal
......
This diff is collapsed.
......@@ -45,6 +45,8 @@ set(${PROJECT_NAME}_HEADERS
dtkWidgetsHUDInfo.h
dtkWidgetsHUDItem
dtkWidgetsHUDItem.h
dtkWidgetsMainWindow
dtkWidgetsMainWindow.h
dtkWidgetsManager
dtkWidgetsManager.h
dtkWidgetsMenu
......@@ -112,6 +114,7 @@ set(${PROJECT_NAME}_SOURCES
dtkWidgetsHUD.cpp
dtkWidgetsHUDInfo.cpp
dtkWidgetsHUDItem.cpp
dtkWidgetsMainWindow.cpp
dtkWidgetsManager.cpp
dtkWidgetsMenu.cpp
dtkWidgetsMenu+ux.cpp
......@@ -152,6 +155,8 @@ target_link_libraries(${PROJECT_NAME} Qt5::WebSockets)
target_link_libraries(${PROJECT_NAME} Qt5::Widgets)
target_link_libraries(${PROJECT_NAME} Qt5::Xml)
target_link_libraries(${PROJECT_NAME} dtkThemes)
target_link_libraries(${PROJECT_NAME} dtkThemesWidgets)
target_link_libraries(${PROJECT_NAME} dtkCore)
target_link_libraries(${PROJECT_NAME} dtkFonts)
target_link_libraries(${PROJECT_NAME} dtkLog)
......
/* dtkApplication.cpp ---
*
* Author: Nicolas Niclausse
* Copyright (C) 2015 - Nicolas Niclausse, Inria.
* Created: 2015/02/04 12:03:44
*/
// Version: $Id$
//
//
/* Commentary:
*
*/
// Commentary:
//
//
/* Change log:
*
*/
// Change Log:
//
//
// Code:
#include "dtkApplication.h"
#include "dtkApplication_p.h"
/*!
\class dtkApplication
\inmodule dtkWidgets
\brief This class is used by GUI applications to provide their event loop. It is based on QApplication, and adds a few command line options to setup settings and dtkLog. It can also be used to start a non GUI appliation if the \tt{-nw} argument is given and the create method is called (it won't work if you use new directly)
\code
int main(int argc, char *argv[])
{
dtkApplication *application = dtkApplication::create(argc, argv);
application->setApplicationName("myApp");
application->setApplicationVersion("1.0.0");
application->setOrganizationName("inria");
application->setOrganizationDomain("fr");
QCommandLineParser *parser = application->parser();
parser->setApplicationDescription("my first DTK based application.");
QCommandLineOption myOption("myopt", "enable myopt");
parser->addOption(myOption);
application->initialize();
if (!parser->isSet(myOption)) {
// do something
}
return application->exec();
}
\endcode
If you run this application, \tt{--help} gives you:
\code
Usage: ./bin/myApp [options]
my first DTK based application.
Options:
--myopt enable myopt
-h, --help Displays this help.
-v, --version Displays version information.
--settings <filename> main settings file
--verbose verbose plugin initialization
--nw, --no-window non GUI application (no window)
--loglevel <level> log level used by dtkLog (default is info),
available: trace|debug|info|warn|error|fatal
--logfile <filename | console> log file used by dtkLog; default is:
/user/nniclaus/home/.local/share/inria/myApp/m
yApp.log
--logfilemax <size> log file max size (in MB); default is: 3072
(3GB)
\endcode
*/
/*! \fn dtkApplication::dtkApplication(int &argc, char **argv)
Constructs a dtkApplication. Initializes the window system and constructs an application object with argc command line arguments in argv.
The argc and argv arguments are processed by the application, and made available in a more convenient form by the arguments() function.
Warning: The data referred to by \a argc and \a argv must stay valid for the entire lifetime of the dtkCoreApplication object. In addition, argc must be greater than zero and argv must contain at least one valid character string.
*/
#include "dtkWidgetsMainWindow.h"
dtkApplication::dtkApplication(int& argc, char **argv): QApplication(argc, argv)
{
d = new dtkApplicationPrivate;
d->setApplication(this);
}
/*! \fn dtkApplication::~dtkApplication(void)
Destroys the dtkApplication object.
*/
this->setAttribute(Qt::AA_EnableHighDpiScaling);
}
dtkApplication::~dtkApplication(void)
{
delete d;
d = NULL;
}
/*! \fn dtkApplication *create(int &argc, char *argv[])
Helper function to create an instance of a dtkApplication. If the \tt{--nw} option is set, it will use a \e{minimal} \tt{QT_QPA_PLATFORM}. \a argc and \a argv are the usual parameters of a QCoreApplication.
*/
/*! \fn Qsettings dtkApplication::settings(void)
Return the main QSettings.
void dtkApplication::initialize(void)
{
d->initialize();
}
*/
void dtkApplication::setup(setup_t setup)
{
setup(this);
}
QSettings *dtkApplication::settings(void)
bool dtkApplication::noGui(void)
{
return d->settings;
return !(qApp && qobject_cast<QGuiApplication *>(qApp) && (QGuiApplication::platformName() != "minimal")) ;
}
dtkApplication *dtkApplication::create(int& argc, char *argv[])
{
for (int i = 0; i < argc; i++)
if(!qstrcmp(argv[i], "-nw") || !qstrcmp(argv[i], "--nw") || !qstrcmp(argv[i], "-no-window") || !qstrcmp(argv[i], "--no-window") || !qstrcmp(argv[i], "-h") || !qstrcmp(argv[i], "--help") || !qstrcmp(argv[i], "--version"))
qputenv("QT_QPA_PLATFORM", QByteArrayLiteral("minimal"));
/*! \fn bool dtkApplication::noGui(void)
return new dtkApplication(argc, argv);
}
Return true if the application is not a GUI application (ie. the \tt{-nw} was used in the command line)
dtkWidgetsMainWindow *dtkApplication::window(void)
{
if(!dtkApplicationPrivate::window)
dtkApplicationPrivate::window = new dtkWidgetsMainWindow;
*/
return dtkApplicationPrivate::window;
}
bool dtkApplication::noGui(void)
int dtkApplication::exec(void)
{
return !(qApp && qobject_cast<QGuiApplication *>(qApp) && (QGuiApplication::platformName() != "minimal")) ;
}
dtkApplication *application = static_cast<dtkApplication *>(qApp);
/*! \fn QCommandLineParser *dtkApplication::parser(void)
if (application->parser()->isSet("theme"))
dtkThemesEngine::instance()->apply(application->parser()->value("theme"));
else
dtkThemesEngine::instance()->apply();
Return the main QCommandLineParser used by the application. It can be used to app specific options for your application.
application->window()->resize(1024, 600);
application->window()->show();
application->window()->raise();
*/
return QApplication::exec();
}
QCommandLineParser *dtkApplication::parser(void)
{
return d->parser;
}
/*! \fn void dtkApplication::initialize(void)
Initialize the command line parser. Should be called once all the specific options of your application are added in the parser.
\sa parser
*/
void dtkApplication::initialize(void)
QSettings *dtkApplication::settings(void)
{
d->initialize();
return d->settings;
}
//
// dtkApplication.cpp ends here
......@@ -14,43 +14,48 @@
#pragma once
#include <dtkWidgetsExport.h>
#include <dtkLog>
#include <QtCore>
#include <QtWidgets>
class dtkApplicationPrivate;
#include <dtkLog>
#include <dtkWidgetsExport.h>
class dtkWidgetsMainWindow;
class DTKWIDGETS_EXPORT dtkApplication: public QApplication
class DTKWIDGETS_EXPORT dtkApplication : public QApplication
{
public:
typedef void (*setup_t)(dtkApplication *);
public:
dtkApplication(int& argc, char **argv);
virtual ~dtkApplication(void);
public:
virtual void initialize(void);
virtual void setup(setup_t);
public:
virtual bool noGui(void);
public:
static dtkApplication *create(int& argc, char *argv[]) {
for (int i = 0; i < argc; i++) {
if (!qstrcmp(argv[i], "-nw") || !qstrcmp(argv[i], "--nw") || !qstrcmp(argv[i], "-no-window") || !qstrcmp(argv[i], "--no-window") || !qstrcmp(argv[i], "-h") || !qstrcmp(argv[i], "--help") || !qstrcmp(argv[i], "--version")) {
qputenv("QT_QPA_PLATFORM", QByteArrayLiteral("minimal"));
}
}
static dtkApplication *create(int& argc, char *argv[]);
public:
static dtkWidgetsMainWindow *window(void);
return new dtkApplication(argc, argv);
}
public:
static int exec(void);
public:
QCommandLineParser *parser(void);
public:
QCommandLineParser *parser(void);
QSettings *settings(void);
QSettings *settings(void);
protected:
dtkApplicationPrivate *d;
class dtkApplicationPrivate *d;
};
//
......
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
// /////////////////////////////////////////////////////////////////////////////
/*!
// /////////////////////////////////////////////////////////////////////////////
\class dtkApplication
\inmodule dtkWidgets
\brief This class is used by GUI applications to provide their event loop. It is
based on QApplication, and adds a few command line options to setup settings and
dtkLog. It can also be used to start a non GUI appliation if the \tt{-nw}
argument is given and the create method is called (it won't work if you use new
directly)
\code
int main(int argc, char *argv[])
{
dtkApplication *application = dtkApplication::create(argc, argv);
application->setApplicationName("myApp");
application->setApplicationVersion("1.0.0");
application->setOrganizationName("inria");
application->setOrganizationDomain("fr");
QCommandLineParser *parser = application->parser();
parser->setApplicationDescription("my first DTK based application.");
QCommandLineOption myOption("myopt", "enable myopt");
parser->addOption(myOption);
application->initialize();
if (!parser->isSet(myOption)) {
// do something
}
return application->exec();
}
\endcode
If you run this application, \tt{--help} gives you:
\code
Usage: ./bin/myApp [options]
my first DTK based application.
Options:
--myopt enable myopt
-h, --help Displays this help.
-v, --version Displays version information.
--settings <filename> main settings file
--verbose verbose plugin initialization
--nw, --no-window non GUI application (no window)
--loglevel <level> log level used by dtkLog (default is info), available: trace|debug|info|warn|error|fatal
--logfile <filename | console> log file used by dtkLog; default is: /user/nniclaus/home/.local/share/inria/myApp/myApp.log
--logfilemax <size> log file max size (in MB); default is: 3072 (3GB)
\endcode
*/
// /////////////////////////////////////////////////////////////////////////////
/*! \fn dtkApplication::dtkApplication(int &argc, char **argv)
// /////////////////////////////////////////////////////////////////////////////
Constructs a dtkApplication. Initializes the window system and constructs an
application object with argc command line arguments in argv.
The argc and argv arguments are processed by the application, and made available
in a more convenient form by the arguments() function.
Warning: The data referred to by \a argc and \a argv must stay valid for the
entire lifetime of the dtkCoreApplication object. In addition, argc must be
greater than zero and argv must contain at least one valid character string.
*/
// /////////////////////////////////////////////////////////////////////////////
/*! \fn dtkApplication::~dtkApplication(void)
// /////////////////////////////////////////////////////////////////////////////
Destroys the dtkApplication object.
*/
// /////////////////////////////////////////////////////////////////////////////
/*! \fn dtkApplication *create(int &argc, char *argv[])
// /////////////////////////////////////////////////////////////////////////////
Helper function to create an instance of a dtkApplication. If the \tt{--nw}
option is set, it will use a \e{minimal} \tt{QT_QPA_PLATFORM}. \a argc and \a
argv are the usual parameters of a QCoreApplication.
*/
// /////////////////////////////////////////////////////////////////////////////
/*! \fn Qsettings dtkApplication::settings(void)
// /////////////////////////////////////////////////////////////////////////////
Returns the main settings.
*/
// /////////////////////////////////////////////////////////////////////////////
/*! \fn bool dtkApplication::noGui(void)
// /////////////////////////////////////////////////////////////////////////////
Returns true if the application is not a GUI application (ie. the \tt{-nw} was
used in the command line)
*/
// /////////////////////////////////////////////////////////////////////////////
/*! \fn QCommandLineParser *dtkApplication::parser(void)
// /////////////////////////////////////////////////////////////////////////////
Return the main QCommandLineParser used by the application. It can be used to
app specific options for your application.
*/
// /////////////////////////////////////////////////////////////////////////////
/*! \fn void dtkApplication::initialize(void)
// /////////////////////////////////////////////////////////////////////////////
Initialize the command line parser. Should be called once all the specific
options of your application are added in the parser.
\sa parser
*/
//
// dtkApplication.qdoc ends here
......@@ -14,24 +14,47 @@
#pragma once
#include <dtkWidgetsExport>
#include <QtCore>
#include <QtWidgets>
class DTKWIDGETS_EXPORT dtkApplicationPrivate
#include <dtkWidgetsExport.h>
// /////////////////////////////////////////////////////////////////////////////
//
// /////////////////////////////////////////////////////////////////////////////
class dtkWidgetsMainWindow;
// /////////////////////////////////////////////////////////////////////////////
//
// /////////////////////////////////////////////////////////////////////////////
class dtkApplicationPrivate
{
public:
class QSettings *settings = nullptr;
class QCommandLineParser *parser = nullptr;
class QCoreApplication *app = nullptr;
dtkApplicationPrivate(void);
~dtkApplicationPrivate(void);
public:
dtkApplicationPrivate(void);
virtual ~dtkApplicationPrivate(void);
virtual void initialize(void);
void initialize(void);
public:
void setApplication(QCoreApplication *app);
public:
QSettings *settings = nullptr;
QCommandLineParser *parser = nullptr;
QCoreApplication *app = nullptr;
public:
static dtkWidgetsMainWindow *window;
};
dtkWidgetsMainWindow *dtkApplicationPrivate::window = nullptr;
// /////////////////////////////////////////////////////////////////////////////
//
// /////////////////////////////////////////////////////////////////////////////
dtkApplicationPrivate::dtkApplicationPrivate(void) : settings(nullptr), parser(new QCommandLineParser), app(nullptr)
{
......@@ -46,6 +69,7 @@ dtkApplicationPrivate::~dtkApplicationPrivate(void)
}
delete this->parser;
this->parser = nullptr;
}
......@@ -56,13 +80,14 @@ void dtkApplicationPrivate::setApplication(QCoreApplication *q)
void dtkApplicationPrivate::initialize(void)
{
// unset QT_PLUGIN_PATH, otherwise, kde plugins can change the qmetatype ids
QString verbosity = "info";
qputenv("QT_PLUGIN_PATH", "1");
qputenv("LC_ALL", "C");
QLocale::setDefault(QLocale::c());
#if defined (Q_OS_UNIX) && !defined(Q_OS_MAC)
// to avoid troubles with floats separators ('.' and not ',')
setlocale(LC_NUMERIC, "C");
#endif
......@@ -78,7 +103,6 @@ void dtkApplicationPrivate::initialize(void)
QCommandLineOption nonguiOption(QStringList() << "nw" << "no-window", QCoreApplication::translate("main", "non GUI application (no window)"));
this->parser->addOption(nonguiOption);
QString verbosity = "info";
QCommandLineOption loglevelOption("loglevel", "log level used by dtkLog (default is info), available: trace|debug|info|warn|error|fatal", "level", verbosity);
this->parser->addOption(loglevelOption);
......@@ -88,37 +112,42 @@ void dtkApplicationPrivate::initialize(void)
QCommandLineOption logfileMaxSizeOption("logfilemax", "log file max size (in MB); default is: 3072 (3GB)", "size");
this->parser->addOption(logfileMaxSizeOption);
QCommandLineOption themeOption("theme", "theme", "themename");
this->parser->addOption(themeOption);
this->parser->process(*(this->app));
if (this->parser->isSet(settingsOption)) {
if (this->parser->isSet(settingsOption))
this->settings = new QSettings(this->parser->value(settingsOption), QSettings::IniFormat);
} else {
else
this->settings = new QSettings(this->app->organizationName(), this->app->applicationName());
}
if (settings->contains("log_level")) {
dtkLogger::instance().setLevel(settings->value("log_level").toString());
} else {
if (this->parser->isSet(loglevelOption)) {
if (this->parser->isSet(loglevelOption))
verbosity = this->parser->value(loglevelOption);
}
dtkLogger::instance().setLevel(verbosity);
}
qlonglong max_size = 1024L * 1024L * 1024L;
if (this->parser->isSet(logfileMaxSizeOption)) {
if (this->parser->isSet(logfileMaxSizeOption))
max_size = this->parser->value(logfileMaxSizeOption).toLongLong() * 1024 * 1024;
}
if (this->parser->isSet(logfileOption)) {
if (this->parser->value(logfileOption) == "console") {
if (this->parser->value(logfileOption) == "console")
dtkLogger::instance().attachConsole();
} else {
else
dtkLogger::instance().attachFile(this->parser->value(logfileOption), max_size);
}
} else {
dtkLogger::instance().attachFile(dtkLogPath(this->app), max_size);
}
}
......
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#include "dtkApplication.h"
#include "dtkWidgets.h"
#include "dtkWidgetsColorButton.h"
#include "dtkWidgetsController.h"
......@@ -11,6 +26,7 @@
#include "dtkWidgetsLayoutItem.h"
#include "dtkWidgetsList.h"
#include "dtkWidgetsListControl.h"
#include "dtkWidgetsMainWindow.h"
#include "dtkWidgetsManager.h"
#include "dtkWidgetsMenuBar.h"
#include "dtkWidgetsMenu.h"
......@@ -31,3 +47,6 @@
#include "dtkWidgetsWorkspace.h"
#include "dtkWidgetsWorkspaceBar.h"
#include "dtkWidgetsWorkspaceStackBar.h"
//
// dtkWidgets ends here
#include "dtkWidgetsMainWindow.h"
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#include "dtkWidgetsMainWindow.h"
#include "dtkWidgetsMenu.h"
#include "dtkWidgetsMenuBar.h"
class dtkWidgetsMainWindowPrivate
{
public:
dtkWidgetsMenuBar *menubar = nullptr;
};
dtkWidgetsMainWindow::dtkWidgetsMainWindow(QWidget *parent) : dtkThemesWidgetsMainWindow(parent)
{
d = new dtkWidgetsMainWindowPrivate;
}
dtkWidgetsMainWindow::~dtkWidgetsMainWindow(void)
{
delete d;
}
dtkWidgetsMenuBar *dtkWidgetsMainWindow::menubar(void)
{
if(!d->menubar)
d->menubar = new dtkWidgetsMenuBar(this);
return d->menubar;
}
void dtkWidgetsMainWindow::resizeEvent(QResizeEvent *event)
{
dtkThemesWidgetsMainWindow::resizeEvent(event);
d->menubar->setFixedHeight(event->size().height());
}
//
// dtkWidgetsMainWindow.cpp ends here
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#pragma once
#include <QtCore>
#include <QtWidgets>
#include <dtkThemes>
#include <dtkThemesWidgets>
#include <dtkWidgetsExport.h>
class dtkWidgetsMenuBar;
class DTKWIDGETS_EXPORT dtkWidgetsMainWindow : public dtkThemesWidgetsMainWindow
{
Q_OBJECT
public:
dtkWidgetsMainWindow(QWidget *parent = nullptr);
~dtkWidgetsMainWindow(void);
public:
dtkWidgetsMenuBar *menubar(void);
protected:
void resizeEvent(QResizeEvent *event);
private:
class dtkWidgetsMainWindowPrivate *d;
};
//
// dtkWidgetsMainWindow.h ends here
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