Added language setting and dialog
This commit is contained in:
27
dialogs/languageselectiondialog.cpp
Normal file
27
dialogs/languageselectiondialog.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#include "languageselectiondialog.h"
|
||||
#include "ui_languageselectiondialog.h"
|
||||
|
||||
LanguageSelectionDialog::LanguageSelectionDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::LanguageSelectionDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
ui->comboBoxLanguage->addItem(tr("English"), QLocale::English);
|
||||
ui->comboBoxLanguage->addItem(tr("German"), QLocale::German);
|
||||
}
|
||||
|
||||
LanguageSelectionDialog::~LanguageSelectionDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
QLocale::Language LanguageSelectionDialog::language() const
|
||||
{
|
||||
return ui->comboBoxLanguage->currentData().value<QLocale::Language>();
|
||||
}
|
||||
|
||||
void LanguageSelectionDialog::setLanguage(QLocale::Language language)
|
||||
{
|
||||
ui->comboBoxLanguage->setCurrentIndex(ui->comboBoxLanguage->findData(language));
|
||||
}
|
24
dialogs/languageselectiondialog.h
Normal file
24
dialogs/languageselectiondialog.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef LANGUAGESELECTIONDIALOG_H
|
||||
#define LANGUAGESELECTIONDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QLocale>
|
||||
|
||||
namespace Ui { class LanguageSelectionDialog; }
|
||||
|
||||
class LanguageSelectionDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit LanguageSelectionDialog(QWidget *parent = 0);
|
||||
~LanguageSelectionDialog();
|
||||
|
||||
QLocale::Language language() const;
|
||||
void setLanguage(QLocale::Language language);
|
||||
|
||||
private:
|
||||
Ui::LanguageSelectionDialog *ui;
|
||||
};
|
||||
|
||||
#endif // LANGUAGESELECTIONDIALOG_H
|
98
dialogs/languageselectiondialog.ui
Normal file
98
dialogs/languageselectiondialog.ui
Normal file
@@ -0,0 +1,98 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>LanguageSelectionDialog</class>
|
||||
<widget class="QDialog" name="LanguageSelectionDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>157</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Language selection</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,1,0">
|
||||
<item>
|
||||
<widget class="QLabel" name="labelTitle">
|
||||
<property name="text">
|
||||
<string><h1>Language selection</h1></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Please select a language:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="labelLanguage">
|
||||
<property name="text">
|
||||
<string>Language:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="comboBoxLanguage"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>LanguageSelectionDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>LanguageSelectionDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
26
main.cpp
26
main.cpp
@@ -4,7 +4,10 @@
|
||||
#include <QInputDialog>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#include "zeiterfassungsettings.h"
|
||||
#include "dialogs/languageselectiondialog.h"
|
||||
#include "zeiterfassung.h"
|
||||
#include "eventloopwithstatus.h"
|
||||
#include "dialogs/authenticationdialog.h"
|
||||
@@ -25,12 +28,10 @@ int main(int argc, char *argv[])
|
||||
"%{function}(): "
|
||||
"%{message}");
|
||||
|
||||
QLocale::setDefault(QLocale(QLocale::German, QLocale::Austria));
|
||||
|
||||
QCoreApplication::setOrganizationDomain(QStringLiteral("brunner.ninja"));
|
||||
QCoreApplication::setOrganizationName(QStringLiteral("db-software"));
|
||||
QCoreApplication::setApplicationName(QStringLiteral("zeiterfassung"));
|
||||
QCoreApplication::setApplicationVersion(QStringLiteral("1.0"));
|
||||
QCoreApplication::setApplicationVersion(QStringLiteral("1.1"));
|
||||
|
||||
QSplashScreen splashScreen(QPixmap(":/zeiterfassung/images/splash.png"));
|
||||
splashScreen.showMessage(QObject::tr("Loading settings..."));
|
||||
@@ -38,6 +39,25 @@ int main(int argc, char *argv[])
|
||||
|
||||
ZeiterfassungSettings settings(&app);
|
||||
|
||||
if(settings.language() == QLocale::AnyLanguage)
|
||||
{
|
||||
LanguageSelectionDialog dialog(&splashScreen);
|
||||
|
||||
again0:
|
||||
if(dialog.exec() != QDialog::Accepted)
|
||||
return -1;
|
||||
|
||||
if(dialog.language() == QLocale::AnyLanguage)
|
||||
{
|
||||
QMessageBox::warning(&splashScreen, QObject::tr("Invalid language selection!"), QObject::tr("You did not select a valid language!"));
|
||||
goto again0;
|
||||
}
|
||||
|
||||
settings.setLanguage(dialog.language());
|
||||
}
|
||||
|
||||
QLocale::setDefault(QLocale(settings.language(), QLocale::Austria));
|
||||
|
||||
splashScreen.showMessage(QObject::tr("Loading login page..."));
|
||||
|
||||
Zeiterfassung erfassung(settings.url(), &app);
|
||||
|
@@ -29,7 +29,8 @@ SOURCES += main.cpp \
|
||||
strips/buchungstrip.cpp \
|
||||
strips/kontierungstrip.cpp \
|
||||
zeiterfassungsettings.cpp \
|
||||
dialogs/settingsdialog.cpp
|
||||
dialogs/settingsdialog.cpp \
|
||||
dialogs/languageselectiondialog.cpp
|
||||
|
||||
HEADERS += \
|
||||
zeiterfassung.h \
|
||||
@@ -44,7 +45,8 @@ HEADERS += \
|
||||
strips/buchungstrip.h \
|
||||
strips/kontierungstrip.h \
|
||||
zeiterfassungsettings.h \
|
||||
dialogs/settingsdialog.h
|
||||
dialogs/settingsdialog.h \
|
||||
dialogs/languageselectiondialog.h
|
||||
|
||||
RESOURCES += \
|
||||
resources.qrc
|
||||
@@ -57,4 +59,5 @@ FORMS += \
|
||||
dialogs/kontierungdialog.ui \
|
||||
strips/buchungstrip.ui \
|
||||
strips/kontierungstrip.ui \
|
||||
dialogs/settingsdialog.ui
|
||||
dialogs/settingsdialog.ui \
|
||||
dialogs/languageselectiondialog.ui
|
||||
|
@@ -32,6 +32,16 @@ ZeiterfassungSettings::ZeiterfassungSettings(QObject *parent) :
|
||||
|
||||
}
|
||||
|
||||
QLocale::Language ZeiterfassungSettings::language() const
|
||||
{
|
||||
return value("language").value<QLocale::Language>();
|
||||
}
|
||||
|
||||
void ZeiterfassungSettings::setLanguage(QLocale::Language language)
|
||||
{
|
||||
setValue("language", language);
|
||||
}
|
||||
|
||||
QString ZeiterfassungSettings::url() const
|
||||
{
|
||||
return value("url", QStringLiteral("http://10.1.0.11:8080/evoApps/")).toString();
|
||||
|
@@ -2,6 +2,7 @@
|
||||
#define ZEITERFASSUNGSETTINGS_H
|
||||
|
||||
#include <QSettings>
|
||||
#include <QLocale>
|
||||
|
||||
class ZeiterfassungSettings : public QSettings
|
||||
{
|
||||
@@ -17,6 +18,9 @@ public:
|
||||
ZeiterfassungSettings(const QString &fileName, Format format, QObject *parent = Q_NULLPTR);
|
||||
explicit ZeiterfassungSettings(QObject *parent = Q_NULLPTR);
|
||||
|
||||
QLocale::Language language() const;
|
||||
void setLanguage(QLocale::Language language);
|
||||
|
||||
QString url() const;
|
||||
void setUrl(const QString &url);
|
||||
|
||||
|
Reference in New Issue
Block a user