Skip to content

Commit

Permalink
Added settings dialog.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ugnius committed Jun 12, 2018
1 parent c7681cd commit d893c58
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.5)

project(instant_translator)

set (CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 11)

# Place binaries and libraries according to GNU standards.
include(GNUInstallDirs)
Expand Down
5 changes: 4 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ set(OTHER_LIBRARIES
glog)

# UI files.
qt5_wrap_ui(UI_HEADERS mainwindow.ui)
qt5_wrap_ui(UI_HEADERS mainwindow.ui dialogs/settingsdialog.ui)

set(RESOURCE_FILES
resources.qrc)
Expand All @@ -42,6 +42,9 @@ set(SOURCE_FILES
apis/api.h
apis/googleapi.cpp
apis/googleapi.h
dialogs/settingsdialog.cpp
dialogs/settingsdialog.h
dialogs/settingsdialog.ui
utils/language.cpp
utils/language.h
utils/requestmanager.cpp
Expand Down
12 changes: 12 additions & 0 deletions src/dialogs/settingsdialog.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "settingsdialog.h"
#include "ui_settingsdialog.h"

SettingsDialog::SettingsDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::SettingsDialog) {
ui->setupUi(this);
}

SettingsDialog::~SettingsDialog() {
delete ui;
}
32 changes: 32 additions & 0 deletions src/dialogs/settingsdialog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#ifndef INSTANT_TRANSLATOR_SETTINGSDIALOG_H
#define INSTANT_TRANSLATOR_SETTINGSDIALOG_H

#include <QDialog>

namespace Ui {
class SettingsDialog;
}

/**
* Settings dialog class.
*/
class SettingsDialog : public QDialog {
Q_OBJECT

public:
/**
* Constructs an object with parent object parent.
* @param parent Parent of an object may be viewed as the object's owner.
*/
explicit SettingsDialog(QWidget *parent = nullptr);

/**
* Destructor.
*/
~SettingsDialog();

private:
Ui::SettingsDialog *ui;
};

#endif // INSTANT_TRANSLATOR_SETTINGSDIALOG_H
68 changes: 68 additions & 0 deletions src/dialogs/settingsdialog.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SettingsDialog</class>
<widget class="QDialog" name="SettingsDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="geometry">
<rect>
<x>30</x>
<y>240</y>
<width>341</width>
<height>32</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>SettingsDialog</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>SettingsDialog</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>
10 changes: 9 additions & 1 deletion src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ MainWindow::MainWindow(QWidget *parent) :

// Load supported languages in the combo boxes.
loadLanguagesInComboBoxes();

settingsDialog = new SettingsDialog(this);
}

MainWindow::~MainWindow() {
Expand Down Expand Up @@ -167,6 +169,12 @@ void MainWindow::on_exitAction_triggered() {
this->close();
}

void MainWindow::on_settingsAction_triggered() {
if (settingsDialog) {
settingsDialog->show();
}
}

void MainWindow::on_translateButton_clicked() {
// Perform translation.
doTranslation();
Expand All @@ -175,4 +183,4 @@ void MainWindow::on_translateButton_clicked() {
void MainWindow::on_swapLanguagesButton_clicked() {
// Swap languages in the combo boxes.
swapLanguagesInComboBoxes();
}
}
15 changes: 11 additions & 4 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#ifndef INSTANT_TRANSLATOR_MAINWINDOW_H
#define INSTANT_TRANSLATOR_MAINWINDOW_H

#include <stdexcept>
#include <QMainWindow>
Expand All @@ -12,6 +12,7 @@
#include <glog/logging.h>
#include "apis/api.h"
#include "apis/googleapi.h"
#include "dialogs/settingsdialog.h"
#include "utils/language.h"

namespace Ui {
Expand Down Expand Up @@ -44,10 +45,15 @@ private slots:
void onClipboardDataChanged();

/**
* On exitAction is changed.
* On exitAction is triggered.
*/
void on_exitAction_triggered();

/**
* On settingsAction is triggered.
*/
void on_settingsAction_triggered();

/**
* On translateButton clicked.
*/
Expand Down Expand Up @@ -102,9 +108,10 @@ private slots:
void showErrorBox(const QString &message);

Ui::MainWindow *ui; // MainWindow user interface.
SettingsDialog *settingsDialog;
QClipboard *clipboard; // Clipboard information.
API *api; // Translation API.
Language language; // Language.
};

#endif // MAINWINDOW_H
#endif // INSTANT_TRANSLATOR_MAINWINDOW_H
13 changes: 10 additions & 3 deletions src/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,29 @@
<x>0</x>
<y>0</y>
<width>600</width>
<height>22</height>
<height>20</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
<widget class="QMenu" name="fileMenu">
<property name="title">
<string>&amp;File</string>
</property>
<addaction name="settingsAction"/>
<addaction name="separator"/>
<addaction name="exitAction"/>
</widget>
<addaction name="menuFile"/>
<addaction name="fileMenu"/>
</widget>
<action name="exitAction">
<property name="text">
<string>E&amp;xit</string>
</property>
</action>
<action name="settingsAction">
<property name="text">
<string>Settings</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
Expand Down

0 comments on commit d893c58

Please sign in to comment.