ui, logic: design for license ui and forcing the user to enter a key on first open

This change integrates the license key ui into the application and makes it necessary for the user to enter a correct
key. The check for a correct key is done on startup and whenever a project is loaded. The check for the key also
includes a check whether the location of the application has changed.
This commit is contained in:
Eberhard Graether
2016-01-18 11:42:31 +01:00
parent 23257a3071
commit 75b102a528
25 changed files with 397 additions and 145 deletions
+4 -2
View File
@@ -74,12 +74,13 @@ set(EIGEN_ROOT $ENV{EIGEN_DIR})
# Botan -------------------------------------------------------------------------
include(cmake/BotanConfig.cmake)
# include(cmake/BotanConfig.cmake)
set(BOTAN_ROOT ${BOTAN_DIR})
set(BOTAN_ROOT $ENV{BOTAN_DIR})
FIND_PACKAGE ( Threads REQUIRED )
message(STATUS ${BOTAN_ROOT})
add_library(BOTAN STATIC ${BOTAN_ROOT}/botan_all.cpp)
target_link_libraries(BOTAN ${CMAKE_THREAD_LIBS_INIT})
@@ -475,6 +476,7 @@ set_property(
target_include_directories(${GEN_PROJECT_NAME} SYSTEM
PUBLIC "${BOTAN_ROOT}"
${Boost_INCLUDE_DIRS}
)
target_link_libraries(${GEN_PROJECT_NAME} BOTAN ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES} )
+6
View File
@@ -10,6 +10,7 @@
* Clang & LLVM (installation guide http://clang.llvm.org/docs/LibASTMatchersTutorial.html)
* Boost 1.59
* Eigen 3.2.6
* Botan 1.11.24
##### Environment Variables
@@ -18,11 +19,16 @@
* CLANG_DIR - .../clang-llvm/
* BOOST_159_DIR - .../boost_1_59_0
* EIGEN_DIR - .../eigen
* BOTAN_DIR -
For Win32:
* VLD_DIR - .../Visual Leak Detector
* path - apped path to git.exe
###### Botan setup
$ ./configure.py --via-amalgamation --minimized-build --enable-modules="base,ecdsa,emsa1,passhash9,rng,rsa,egd,emsa_pssr,emsa_pkcs1,x509,aes,dev_random"
##### Settings
Run setup script:
+17
View File
@@ -0,0 +1,17 @@
#licenseField {
font-family: "<setting:font_name>";
font-size: 12pt;
height: 200px;
padding: 5px;
width: 470px;
}
#licenseError {
color: red;
}
QTextEdit {
background-color: rgba(255, 255, 255, 200);
border-radius: 10px;
border: 1px solid lightgrey;
}
@@ -75,3 +75,13 @@ QLineEdit:disabled {
color: white;
background: #2D3F85;
}
#windowButton:disabled {
color: lightgray;
}
QToolTip {
background-color: <color:tool_tip/background>;
color: <color:tool_tip/text>;
font-size: <setting:font_size>pt;
}
+2 -2
View File
@@ -1,10 +1,10 @@
#ifndef PUBLIC_KEY_H
#define PUBLIC_KEY_H
// This File(PublicKey.h) is generated with CMake
// This File(PublicKey.h) is generated with CMake
#include <string>
static const std::string PublicKey = "@KEY@";
#endif //PUBLIC_KEY_H
#endif // PUBLIC_KEY_H
+1
View File
@@ -4,5 +4,6 @@ add_files(
data/parser/cxx/TaskParseCxx.cpp
isTrial.cpp
LicenseChecker.h
main.cpp
)
+78
View File
@@ -0,0 +1,78 @@
#ifndef LICENSE_CHECKER_H
#define LICENSE_CHECKER_H
#include "utility/messaging/MessageListener.h"
#include "utility/messaging/type/MessageLoadProject.h"
#include "utility/messaging/type/MessageStatus.h"
#include "License.h"
#include "PublicKey.h"
#include "settings/ApplicationSettings.h"
class LicenseChecker
: public MessageListener<MessageLoadProject>
{
public:
inline void setApp(Application* app)
{
m_app = app;
if (!checkLicenseString())
{
m_app->showLicenseScreen();
}
}
private:
void handleMessage(MessageLoadProject* message)
{
if (!checkLicenseString())
{
message->cancel();
m_app->showLicenseScreen();
}
}
inline bool checkLicenseString()
{
MessageStatus("preparing...", false, true).dispatch();
bool valid = false;
do
{
ApplicationSettings* appSettings = ApplicationSettings::getInstance().get();
std::string licenseCheck = appSettings->getLicenseCheck();
FilePath p("");
if (!License::checkLocation(p.absolute().str(), licenseCheck))
{
break;
}
std::string licenseString = appSettings->getLicenseString();
if (licenseString.size() == 0)
{
break;
}
License license;
bool isLoaded = license.loadFromString(licenseString);
if (!isLoaded)
{
break;
}
license.loadPublicKeyFromString(PublicKey);
valid = license.isValid();
}
while (false);
MessageStatus("ready").dispatch();
return valid;
}
Application* m_app;
};
#endif // LICENSE_CHECKER_H
+6
View File
@@ -9,6 +9,7 @@
#include "Application.h"
#include "includes.h" // defines 'void setup(int argc, char *argv[])'
#include "LicenseChecker.h"
#include "qt/commandline/QtCommandLineParser.h"
#include "qt/window/QtMainWindow.h"
#include "qt/window/QtSplashScreen.h"
@@ -63,8 +64,13 @@ int main(int argc, char *argv[])
QtMainWindow::setWindowSettingsPath(windowSettingsPath);
Application::setAppSettingsPath(appSettingsPath);
LicenseChecker checker;
std::shared_ptr<Application> app = Application::create(version, &viewFactory, &networkFactory);
checker.setApp(app.get());
if (splash)
{
delete splash;
+34 -67
View File
@@ -23,12 +23,12 @@ License::~License()
{
}
std::string License::getHashLine()
std::string License::getHashLine() const
{
return lines[4];
}
std::string License::getMessage()
std::string License::getMessage() const
{
std::string message = "";
for(int i = 1; i < 5; ++i)
@@ -38,7 +38,7 @@ std::string License::getMessage()
return message;
}
std::string License::getSignature()
std::string License::getSignature() const
{
std::string signatue = "";
for(int i = 5; i < 12; ++i)
@@ -48,11 +48,21 @@ std::string License::getSignature()
return signatue;
}
std::string License::getVersionLine()
std::string License::getVersionLine() const
{
return lines[3];
}
std::string License::getOwnerLine() const
{
return lines[1];
}
std::string License::getLicenseTypeLine() const
{
return lines[2];
}
void License::create(std::string user, std::string version, Botan::RSA_PrivateKey* privateKey, unsigned int type)
{
m_version = version;
@@ -109,62 +119,28 @@ bool License::load(std::istream& stream)
{
lines.clear();
std::string line;
if(!getline(stream, line, '\n'))
while (getline(stream, line, '\n'))
{
return false;
lines.push_back(line);
}
if(line.compare(BEGIN_LICENSE) )
if (lines.front() != BEGIN_LICENSE)
{
std::cout << "No License Header" << std::endl;
lines.push_back(BEGIN_LICENSE);
lines.insert(lines.begin(), BEGIN_LICENSE);
}
else
{
lines.push_back(line);
if(!getline(stream, line))
{
return false;
}
}
lines.push_back(line);
for(int i = 0; i < 2; ++i)
if (lines.back() != END_LICENSE)
{
if(!getline(stream, line))
{
return false;
}
lines.push_back(line);
std::cout << "No License Footer" << std::endl;
lines.push_back(END_LICENSE);
}
if(!getline(stream, line))
if (lines.size() != 13)
{
return false;
}
lines.push_back(line);
//get signature
std::string signature = "";
for(int i = 0; i < 7; ++i)
{
if(!getline(stream, line))
{
return false;
}
signature += line;
lines.push_back(line);
}
//check License ending
getline(stream, line);
if(line.compare(END_LICENSE))
{
std::cout << "No License Footer" << std::endl;
lines.push_back(END_LICENSE);
}
else
{
lines.push_back(line);
}
return true;
}
@@ -181,16 +157,6 @@ void License::print()
std::cout << getLicenseString();
}
std::string License::getOwnerLine()
{
return lines[1];
}
std::string License::getLicenseTypeLine()
{
return lines[2];
}
void License::addSignature(std::string signature)
{
if(lines.size() > 5)
@@ -215,7 +181,7 @@ void License::addSignature(std::string signature)
lines.push_back(END_LICENSE);
}
bool License::isValid()
bool License::isValid() const
{
if(!m_publicKey)
{
@@ -242,7 +208,7 @@ bool License::isValid()
return ok;
}
std::string License::getPublicKeyFilename()
std::string License::getPublicKeyFilename() const
{
if(m_publicKeyFilename.empty())
{
@@ -251,7 +217,8 @@ std::string License::getPublicKeyFilename()
return m_publicKeyFilename;
}
std::string License::getVersion() {
std::string License::getVersion() const
{
if(m_version.empty())
{
return "x";
@@ -298,7 +265,7 @@ void License::setVersion(const std::string& version)
}
}
std::string License::getLicenseString()
std::string License::getLicenseString() const
{
std::stringstream license;
for(std::string line : lines)
@@ -308,12 +275,12 @@ std::string License::getLicenseString()
return license.str();
}
bool License::checkLocation(const std::string& location, const std::string& hash)
{
return Botan::check_passhash9(location, hash);
}
std::string License::hashLocation(const std::string& location)
{
return Botan::generate_passhash9(location, m_rng);
}
bool License::checkLocation(const std::string& location, const std::string& hash)
{
return Botan::check_passhash9(location, hash);
}
+17 -13
View File
@@ -11,28 +11,30 @@
//#include "botan/rsa.h"
#endif
class License {
class License
{
public:
enum LicenseType
{
LICENSETYPE_SINGLEUSER = 0,
};
License();
~License();
std::string getHashLine();
std::string getMessage();
std::string getSignature();
std::string getVersionLine();
std::string getOwnerLine();
std::string getLicenseTypeLine();
std::string getHashLine() const;
std::string getMessage() const;
std::string getSignature() const;
std::string getVersionLine() const;
std::string getOwnerLine() const;
std::string getLicenseTypeLine() const;
std::string getPublicKeyFilename();
std::string getVersion();
std::string getPublicKeyFilename() const;
std::string getVersion() const;
void create(std::string user, std::string version, Botan::RSA_PrivateKey* privateKey, unsigned int type = 0);
std::string getLicenseString();
std::string getLicenseString() const;
void writeToFile(std::string filename);
bool load(std::istream& stream);
@@ -43,15 +45,17 @@ public:
bool loadPublicKeyFromString(std::string);
void setVersion(const std::string&);
bool isValid();
bool isValid() const;
void print();
std::string hashLocation(const std::string&);
bool checkLocation(const std::string&, const std::string&);
static bool checkLocation(const std::string&, const std::string&);
private:
void createMessage(std::string user, std::string version, unsigned int type = 0);
void addSignature(std::string);
std::string m_version;
std::string m_publicKeyFilename;
std::shared_ptr<Botan::RSA_PublicKey> m_publicKey;
@@ -63,4 +67,4 @@ private:
const std::string END_LICENSE = "-----END LICENSE-----";
};
#endif //COATI_LICENSE_H
#endif // COATI_LICENSE_H
+5
View File
@@ -111,6 +111,11 @@ void Application::saveProject(const FilePath& projectSettingsFilePath)
}
}
void Application::showLicenseScreen()
{
m_mainView->showLicenseScreen();
}
void Application::setAppSettingsPath(const std::string& appSettingsPath)
{
m_appSettingsPath = appSettingsPath;
+1
View File
@@ -35,6 +35,7 @@ public:
void loadProject(const FilePath& projectSettingsFilePath, bool forceRefresh);
void refreshProject();
void saveProject(const FilePath& projectSettingsFilePath);
void showLicenseScreen();
static void setAppSettingsPath(const std::string& appSettingsPath);
+1
View File
@@ -16,6 +16,7 @@ public:
virtual void setTitle(const std::string& title) = 0;
virtual void activateWindow() = 0;
virtual void updateRecentProjectMenu() = 0;
virtual void showLicenseScreen() = 0;
};
#endif // MAIN_VIEW_H
+4 -4
View File
@@ -163,20 +163,20 @@ int ApplicationSettings::getControlsMouseForwardButton() const
std::string ApplicationSettings::getLicenseString() const
{
return getValue<std::string>("application/license/license:", "");
return getValue<std::string>("user/license/license", "");
}
std::string ApplicationSettings::getLicenseCheck() const
{
return getValue<std::string>("application/license/check", "");
return getValue<std::string>("user/license/check", "");
}
void ApplicationSettings::setLicenseString(const std::string& licenseString)
{
setValue<std::string>("application/license/license", licenseString);
setValue<std::string>("user/license/license", licenseString);
}
void ApplicationSettings::setLicenseCheck(const std::string& hash)
{
setValue<std::string>("application/license/check", hash);
setValue<std::string>("user/license/check", hash);
}
+12
View File
@@ -19,6 +19,7 @@ public:
: undoRedoType(UNDOTYPE_NORMAL)
, m_sendAsTask(true)
, m_keepContent(false)
, m_cancelled(false)
{
}
@@ -59,6 +60,16 @@ public:
return m_keepContent;
}
void cancel()
{
m_cancelled = true;
}
bool cancelled()
{
return m_cancelled;
}
virtual void print(std::ostream& os) const = 0;
std::string str() const
@@ -74,6 +85,7 @@ public:
private:
bool m_sendAsTask;
bool m_keepContent;
bool m_cancelled;
};
#endif // MESSAGE_BASE_H
+6 -1
View File
@@ -241,6 +241,11 @@ void MessageQueue::sendMessage(std::shared_ptr<MessageBase> message)
listener->handleMessageBase(message.get());
m_listenersMutex.lock();
}
if (message->cancelled())
{
break;
}
}
}
@@ -260,7 +265,7 @@ void MessageQueue::sendMessageAsTask(std::shared_ptr<MessageBase> message, bool
[listenerId, message]()
{
MessageListenerBase* listener = MessageQueue::getInstance()->getListenerById(listenerId);
if (listener)
if (listener && !message->cancelled())
{
listener->handleMessageBase(message.get());
}
+11
View File
@@ -8,6 +8,7 @@ QtMainView::QtMainView()
: m_setTitleFunctor(std::bind(&QtMainView::doSetTitle, this, std::placeholders::_1))
, m_activateWindowFunctor(std::bind(&QtMainView::doActivateWindow, this))
, m_updateRecentProjectMenuFunctor(std::bind(&QtMainView::doUpdateRecentProjectMenu, this))
, m_showLicenseScreenFunctor(std::bind(&QtMainView::doShowLicenseScreen, this))
{
m_window = std::make_shared<QtMainWindow>();
m_window->show();
@@ -86,6 +87,11 @@ void QtMainView::updateRecentProjectMenu()
m_updateRecentProjectMenuFunctor();
}
void QtMainView::showLicenseScreen()
{
m_showLicenseScreenFunctor();
}
void QtMainView::doUpdateRecentProjectMenu()
{
m_window->updateRecentProjectMenu();
@@ -103,3 +109,8 @@ void QtMainView::doActivateWindow()
m_window->raise();
m_window->setFocus(Qt::ActiveWindowFocusReason);
}
void QtMainView::doShowLicenseScreen()
{
m_window->forceEnterLicense();
}
+3
View File
@@ -37,11 +37,13 @@ public:
virtual void setTitle(const std::string& title);
virtual void activateWindow();
virtual void updateRecentProjectMenu();
virtual void showLicenseScreen();
private:
void doSetTitle(const std::string& title);
void doActivateWindow();
void doUpdateRecentProjectMenu();
void doShowLicenseScreen();
std::shared_ptr<QtMainWindow> m_window;
std::vector<View*> m_views;
@@ -49,6 +51,7 @@ private:
QtThreadedFunctor<const std::string&> m_setTitleFunctor;
QtThreadedFunctor<> m_activateWindowFunctor;
QtThreadedFunctor<> m_updateRecentProjectMenuFunctor;
QtThreadedFunctor<> m_showLicenseScreenFunctor;
};
#endif // QT_MAIN_VIEW_H
+103 -32
View File
@@ -10,42 +10,102 @@
#include "License.h"
#include "PublicKey.h"
#include "settings/ApplicationSettings.h"
#include "utility/logging/logging.h"
#include "qt/utility/utilityQt.h"
#include "settings/ApplicationSettings.h"
#include "utility/file/FilePath.h"
QtLicense::QtLicense(QWidget *parent)
: QtSettingsWindow(parent)
: QtSettingsWindow(parent, 68)
{
raise();
}
QSize QtLicense::sizeHint() const
{
return QSize(600,600);
return QSize(725, 550);
}
void QtLicense::clear()
{
if (m_licenseText)
{
m_licenseText->setText("");
}
if (m_errorLabel)
{
m_errorLabel->setText(" ");
}
}
void QtLicense::setup()
{
setupForm();
setStyleSheet((
utility::getStyleSheet("data/gui/setting_window/window.css") +
utility::getStyleSheet("data/gui/license/license.css")
).c_str());
updateTitle("Enter License");
updateDoneButton("Ok");
}
addLogo();
void QtLicense::populateForm(QFormLayout* layout)
{
QLabel* licenseName = new QLabel();
licenseName->setText( QString::fromLatin1("Enter License:"));
QFont _font = licenseName->font();
_font.setPixelSize(36);
licenseName->setFont(_font);
layout->addWidget(licenseName);
QVBoxLayout* layout = new QVBoxLayout(this);
layout->setContentsMargins(25, 100, 25, 30);
m_licenseText = new QTextEdit();
m_licenseText->setMinimumHeight(300);
layout->addWidget(m_licenseText);
QVBoxLayout* subLayout = new QVBoxLayout();
subLayout->setContentsMargins(250, 0, 0, 0);
QLabel* licenseName = new QLabel(this);
licenseName->setText(QString::fromLatin1("Enter Licence"));
licenseName->setObjectName("titleLabel");
subLayout->addWidget(licenseName);
subLayout->addSpacing(10);
QLabel* licenseIntro = new QLabel(this);
licenseIntro->setText(QString::fromLatin1("Please enter a licence key to activate Coati:"));
licenseIntro->setObjectName("licenseIntro");
subLayout->addWidget(licenseIntro);
m_licenseText = new QTextEdit(this);
m_licenseText->setObjectName("licenseField");
m_licenseText->setText(ApplicationSettings::getInstance()->getLicenseString().c_str());
m_licenseText->setPlaceholderText(
"-----BEGIN LICENSE-----\n"
"Jane Doe\n"
"Single User License\n"
"Coati 0\n"
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"
"xxxxxxxxxxxxxx\n"
"-----END LICENSE-----\n"
);
subLayout->addWidget(m_licenseText);
m_errorLabel = new QLabel(this);
m_errorLabel->setObjectName("licenseError");
m_errorLabel->setText(" ");
subLayout->addWidget(m_errorLabel);
subLayout->addSpacing(10);
QLabel* linkLabel = new QLabel(this);
linkLabel->setObjectName("linkLabel");
linkLabel->setText("<a href=\"http://coati.io/buy-license\">Don't have a license key yet?</a>");
linkLabel->setOpenExternalLinks(true);
linkLabel->setGeometry(275, 300, 300, 50);
subLayout->addWidget(linkLabel);
layout->addLayout(subLayout);
layout->addSpacing(20);
showButtons(layout);
updateDoneButton("Activate");
resize(725, 550);
}
void QtLicense::handleCancelButtonPress()
@@ -55,29 +115,40 @@ void QtLicense::handleCancelButtonPress()
void QtLicense::handleUpdateButtonPress()
{
License license;
bool isLoaded = license.loadFromString(m_licenseText->toPlainText().toStdString());
if(!isLoaded)
std::string licenseString = m_licenseText->toPlainText().toStdString();
if (licenseString.size() == 0)
{
LOG_WARNING("Failed Loading License");
m_errorLabel->setText("No licence key was entered.");
return;
}
License license;
bool isLoaded = license.loadFromString(licenseString);
if (!isLoaded)
{
m_errorLabel->setText("The entered license key is malformed.");
return;
}
license.loadPublicKeyFromString(PublicKey);
license.print();
if(license.isValid())
if (license.isValid())
{
ApplicationSettings::getInstance()->setLicenseString(license.getLicenseString());
ApplicationSettings* appSettings = ApplicationSettings::getInstance().get();
appSettings->setLicenseString(license.getLicenseString());
FilePath p("");
ApplicationSettings::getInstance()->setLicenseCheck(license.hashLocation(p.absolute().str()));
ApplicationSettings::getInstance()->save();
LOG_WARNING("License saved");
appSettings->setLicenseCheck(license.hashLocation(p.absolute().str()));
appSettings->save();
}
else
{
LOG_WARNING("License is not valid");
m_errorLabel->setText("The entered license key is invalid.");
return;
}
m_errorLabel->setText(" ");
setCancelAble(true);
emit finished();
}
+3 -3
View File
@@ -16,9 +16,9 @@ public:
QtLicense(QWidget* parent = 0);
QSize sizeHint() const Q_DECL_OVERRIDE;
void clear();
virtual void setup() override;
protected:
virtual void populateForm(QFormLayout* layout) override;
private slots:
void handleCancelButtonPress();
@@ -29,7 +29,7 @@ private:
QPushButton* m_updateButton;
QTextEdit* m_licenseText;
QLabel* m_errorLabel;
};
#endif //QT_LICENSE_H
+18 -2
View File
@@ -243,6 +243,16 @@ void QtMainWindow::saveLayout()
settings.setValue("DOCK_LOCATIONS", this->saveState());
}
void QtMainWindow::forceEnterLicense()
{
enterLicense();
m_enterLicenseWindow->clear();
m_enterLicenseWindow->setCancelAble(false);
this->setEnabled(false);
m_enterLicenseWindow->setEnabled(true);
}
bool QtMainWindow::event(QEvent* event)
{
if (event->type() == QEvent::WindowActivate)
@@ -297,6 +307,12 @@ void QtMainWindow::clearWindows()
m_windowStack.clear();
}
void QtMainWindow::activateWindow()
{
this->setEnabled(true);
popWindow();
}
void QtMainWindow::about()
{
if (!m_aboutWindow)
@@ -345,11 +361,11 @@ void QtMainWindow::enterLicense()
m_enterLicenseWindow = std::make_shared<QtLicense>(this);
m_enterLicenseWindow->setup();
connect(m_enterLicenseWindow.get(), SIGNAL(finished()), this, SLOT(popWindow()));
connect(m_enterLicenseWindow.get(), SIGNAL(finished()), this, SLOT(activateWindow()));
connect(m_enterLicenseWindow.get(), SIGNAL(canceled()), this, SLOT(popWindow()));
}
pushWindow(m_enterLicenseWindow)
pushWindow(m_enterLicenseWindow.get());
}
void QtMainWindow::showStartScreen()
+4
View File
@@ -83,6 +83,8 @@ public:
void loadLayout();
void saveLayout();
void forceEnterLicense();
protected:
bool event(QEvent* event);
void keyPressEvent(QKeyEvent* event);
@@ -92,6 +94,8 @@ public slots:
void popWindow();
void clearWindows();
void activateWindow();
void about();
void openSettings();
void showLicenses();
+43 -13
View File
@@ -18,6 +18,7 @@ QtSettingsWindow::QtSettingsWindow(QWidget *parent, int displacement)
, m_cancelButton(nullptr)
, m_doneButton(nullptr)
, m_mousePressedInWindow(false)
, m_cancelAble(true)
{
QSize windowSize = sizeHint();
move(parent->pos().x() + parent->width() / 2 - 250, parent->pos().y() + parent->height() / 2 - 250);
@@ -60,12 +61,24 @@ QSize QtSettingsWindow::sizeHint() const
return QSize(500, 500);
}
void QtSettingsWindow::setCancelAble(bool cancelable)
{
if (m_cancelButton)
{
m_cancelButton->setEnabled(cancelable);
}
m_cancelAble = cancelable;
}
void QtSettingsWindow::keyPressEvent(QKeyEvent *event)
{
if (event->key() == Qt::Key_Escape)
if (m_cancelAble && event->key() == Qt::Key_Escape)
{
emit canceled();
}
QWidget::keyPressEvent(event);
}
void QtSettingsWindow::resizeEvent(QResizeEvent *event)
@@ -139,6 +152,34 @@ void QtSettingsWindow::setupForm()
form->setLayout(layout);
windowLayout->addWidget(scrollArea);
windowLayout->addSpacing(20);
showButtons(windowLayout);
m_window->setLayout(windowLayout);
resize(QSize(600, 620));
scrollArea->raise();
}
void QtSettingsWindow::populateForm(QFormLayout* layout)
{
}
void QtSettingsWindow::addLogo()
{
QtDeviceScaledPixmap coatiLogo("data/gui/startscreen/logo.png");
coatiLogo.scaleToWidth(200);
QLabel* coatiLogoLabel = new QLabel(this);
coatiLogoLabel->setPixmap(coatiLogo.pixmap());
coatiLogoLabel->resize(coatiLogo.width(), coatiLogo.height());
coatiLogoLabel->move(30,10);
}
void QtSettingsWindow::showButtons(QVBoxLayout* layout)
{
m_cancelButton = new QPushButton("Cancel");
m_cancelButton->setObjectName("windowButton");
m_doneButton = new QPushButton("Done");
@@ -153,18 +194,7 @@ void QtSettingsWindow::setupForm()
buttons->addWidget(m_doneButton);
m_buttonsLayout = buttons;
windowLayout->addWidget(scrollArea);
windowLayout->addSpacing(20);
windowLayout->addLayout(buttons);
m_window->setLayout(windowLayout);
resize(QSize(600, 620));
scrollArea->raise();
}
void QtSettingsWindow::populateForm(QFormLayout* layout)
{
layout->addLayout(buttons);
}
void QtSettingsWindow::updateTitle(QString title)
+7
View File
@@ -8,6 +8,7 @@
class QFormLayout;
class QLabel;
class QPushButton;
class QVBoxLayout;
class QtSettingsWindow
: public QWidget
@@ -21,6 +22,8 @@ public:
virtual void setup() = 0;
void setCancelAble(bool cancelAble);
signals:
void finished();
void canceled();
@@ -35,6 +38,9 @@ protected:
void setupForm();
virtual void populateForm(QFormLayout* layout);
void addLogo();
void showButtons(QVBoxLayout* layout);
void updateTitle(QString title);
void updateDoneButton(QString text);
void hideCancelButton(bool hidden);
@@ -56,6 +62,7 @@ private:
int m_displacment;
QPoint m_dragPosition;
bool m_mousePressedInWindow;
bool m_cancelAble;
};
#endif //QT_SETTINGS_WINDOW_H
+1 -6
View File
@@ -35,12 +35,7 @@ void QtStartScreen::setup()
{
setStyleSheet(utility::getStyleSheet("data/gui/startscreen/startscreen.css").c_str());
QtDeviceScaledPixmap coati_logo("data/gui/startscreen/logo.png");
coati_logo.scaleToWidth(200);
QLabel* coatiLogoLabel = new QLabel(this);
coatiLogoLabel->setPixmap(coati_logo.pixmap());
coatiLogoLabel->resize(coati_logo.width(), coati_logo.height());
coatiLogoLabel->move(30,10);
addLogo();
if(!isTrial())
{