From 9ad3df3f6bf98141d65eb1346262f1544bd659d6 Mon Sep 17 00:00:00 2001 From: Alex Zolotarev Date: Sat, 12 Feb 2011 01:50:42 +0100 Subject: [PATCH] [QT] Added welcome dialog on first launch --- data/welcome.html | 7 ++++++ qt/info_dialog.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++++++ qt/info_dialog.hpp | 20 ++++++++++++++++ qt/mainwindow.cpp | 22 ++++++++++++++++++ qt/qt.pro | 46 ++++++++++++++++++------------------ 5 files changed, 131 insertions(+), 22 deletions(-) create mode 100644 data/welcome.html create mode 100644 qt/info_dialog.cpp create mode 100644 qt/info_dialog.hpp diff --git a/data/welcome.html b/data/welcome.html new file mode 100644 index 0000000000..ce006c5993 --- /dev/null +++ b/data/welcome.html @@ -0,0 +1,7 @@ + + +

Offline World Map in your computer

+

Congratulations! You're just in one step to see yor favourite cities and countries! Download them once and use everywhere - no internet access is needed!

+

We'll try to keep you updated when new application versions and new map data become available. And of course, you always can check latest news on our web site: www.mapswithme.com

+ + diff --git a/qt/info_dialog.cpp b/qt/info_dialog.cpp new file mode 100644 index 0000000000..82770dd59d --- /dev/null +++ b/qt/info_dialog.cpp @@ -0,0 +1,58 @@ +#include "info_dialog.hpp" + +#include +#include +#include +#include +#include + +#include + +namespace qt +{ + InfoDialog::InfoDialog(QString const & title, QString const & text, QWidget * parent) + : QDialog(parent) + { + QIcon icon(":logo.png"); + setWindowIcon(icon); + setWindowTitle(title); + +// QTextEdit * textEdit = new QTextEdit(text, this); +// textEdit->setReadOnly(true); + + QVBoxLayout * vBox = new QVBoxLayout(); + QLabel * label = new QLabel(text); + vBox->addWidget(label); + //vBox->addWidget(textEdit); + // this horizontal layout is for buttons + QHBoxLayout * hBox = new QHBoxLayout(); + vBox->addLayout(hBox); + + setLayout(vBox); + } + + void InfoDialog::OnButtonClick(bool) + { + // @TODO determine which button is pressed + done(0); + } + + void InfoDialog::SetCustomButtons(QStringList const & buttons) + { + QLayout * hBox = layout()->layout(); + // @TODO clear old buttons if any +// for (int i = 0; i < hBox->count(); ++i) +// { +// QLayoutItem * item = hBox->itemAt(i); +// hBox->removeItem(item); +// delete item; +// } + + for (int i = 0; i < buttons.size(); ++i) + { + QPushButton * button = new QPushButton(buttons[i]); + connect(button, SIGNAL(clicked(bool)), this, SLOT(OnButtonClick(bool))); + hBox->addWidget(button); + } + } +} diff --git a/qt/info_dialog.hpp b/qt/info_dialog.hpp new file mode 100644 index 0000000000..5342b7cc33 --- /dev/null +++ b/qt/info_dialog.hpp @@ -0,0 +1,20 @@ +#pragma once + +#include + +namespace qt +{ + /// Simple information dialog with scrollable html content + class InfoDialog : public QDialog + { + Q_OBJECT + public: + /// Default constructor creates dialog without any buttons + explicit InfoDialog(QString const & title, QString const & text, QWidget * parent); + /// Sets buttons in dialog + void SetCustomButtons(QStringList const & buttons); + + public slots: + void OnButtonClick(bool); + }; +} diff --git a/qt/mainwindow.cpp b/qt/mainwindow.cpp index f110c9bc1b..fd17f65b67 100644 --- a/qt/mainwindow.cpp +++ b/qt/mainwindow.cpp @@ -8,6 +8,7 @@ #include "slider_ctrl.hpp" #include "about.hpp" #include "preferences_dialog.hpp" +#include "info_dialog.hpp" #include "../defines.hpp" @@ -72,6 +73,27 @@ MainWindow::MainWindow() : m_updateDialog(0) #endif LoadState(); + + // Show intro dialog if necessary + bool bShow = false; + if (!Settings::Get("ShowWelcome", bShow)) + { + QFile welcomeTextFile(GetPlatform().ReadPathForFile("welcome.html").c_str()); + if (welcomeTextFile.open(QIODevice::ReadOnly)) + { + QByteArray text = welcomeTextFile.readAll(); + welcomeTextFile.close(); + + InfoDialog welcomeDlg(tr("Welcome to MapsWithMe!"), text, this); + QStringList buttons; + buttons << tr("Download Maps"); + welcomeDlg.SetCustomButtons(buttons); + welcomeDlg.exec(); + } + Settings::Set("ShowWelcome", bool(false)); + + ShowUpdateDialog(); + } } #if defined(Q_WS_WIN) diff --git a/qt/qt.pro b/qt/qt.pro index 086447c17e..adee9dd220 100644 --- a/qt/qt.pro +++ b/qt/qt.pro @@ -55,29 +55,31 @@ win32-g++ { } SOURCES += \ - main.cpp \ - mainwindow.cpp \ - searchwindow.cpp \ - widgets.cpp \ - update_dialog.cpp \ - draw_widget.cpp \ - classificator_tree.cpp \ - proxystyle.cpp \ - slider_ctrl.cpp \ - about.cpp \ - preferences_dialog.cpp \ + main.cpp \ + mainwindow.cpp \ + searchwindow.cpp \ + widgets.cpp \ + update_dialog.cpp \ + draw_widget.cpp \ + classificator_tree.cpp \ + proxystyle.cpp \ + slider_ctrl.cpp \ + about.cpp \ + preferences_dialog.cpp \ + info_dialog.cpp HEADERS += \ - mainwindow.hpp \ - searchwindow.hpp \ - widgets.hpp \ - update_dialog.hpp \ - draw_widget.hpp \ - qt_window_handle.hpp \ - classificator_tree.hpp \ - proxystyle.hpp \ - slider_ctrl.hpp \ - about.hpp \ - preferences_dialog.hpp \ + mainwindow.hpp \ + searchwindow.hpp \ + widgets.hpp \ + update_dialog.hpp \ + draw_widget.hpp \ + qt_window_handle.hpp \ + classificator_tree.hpp \ + proxystyle.hpp \ + slider_ctrl.hpp \ + about.hpp \ + preferences_dialog.hpp \ + info_dialog.hpp RESOURCES += res/resources.qrc \