#include "dialogs.hpp" #include #include static QPointer _instance = NULL; static QPointer _currentNote; static QPointer _quickOptionsDialog; static QPointer _backgroundColorButton; static QPointer _foregroundColorButton; static QPointer _fontButton; static QPointer _alphaSlider; Dialogs::Dialogs(QObject *parent) : QObject(parent) { } Dialogs *Dialogs::instance() { if (_instance == NULL) _instance = new Dialogs(QCoreApplication::instance()); return _instance; } void Dialogs::showQuickOptionsDialog() { static bool isShown = false; if (isShown) return; if (_quickOptionsDialog == NULL) { _quickOptionsDialog = new QDialog; _quickOptionsDialog->setWindowTitle("Quick options"); _backgroundColorButton = new QPushButton("Background"); _foregroundColorButton = new QPushButton("Foreground"); _fontButton = new QPushButton("Font"); QPushButton *aboutButton = new QPushButton("About"); _alphaSlider = new QSlider(Qt::Horizontal); _alphaSlider->setMinimum(0); _alphaSlider->setMaximum(255); QHBoxLayout *buttonsLayout = new QHBoxLayout; buttonsLayout->addWidget(_backgroundColorButton); buttonsLayout->addWidget(_foregroundColorButton); buttonsLayout->addWidget(_fontButton); QHBoxLayout *opacityLayout = new QHBoxLayout; opacityLayout->addWidget(new QLabel("Opacity")); opacityLayout->addWidget(_alphaSlider); QVBoxLayout *layout = new QVBoxLayout; layout->addLayout(buttonsLayout); layout->addWidget(aboutButton); layout->addLayout(opacityLayout); _quickOptionsDialog->setLayout(layout); connect(_backgroundColorButton, SIGNAL(clicked()), this, SLOT(showBackgroundColorSelection())); connect(_foregroundColorButton, SIGNAL(clicked()), this, SLOT(showForegroundColorSelection())); connect(_fontButton, SIGNAL(clicked()), this, SLOT(showFontSelection())); connect(aboutButton, SIGNAL(clicked()), this, SLOT(showAboutDialog())); } if (QObject::sender()->inherits("StickyNotesWidget")) { isShown = true; _currentNote = (StickyNotesWidget*)QObject::sender(); if (_currentNote->isReadOnly()) { _foregroundColorButton->hide(); _fontButton->hide(); } else { _foregroundColorButton->show(); _fontButton->show(); } int alpha = _currentNote->backgroundColor().alpha(); if (_alphaSlider->value() != alpha) _alphaSlider->setValue(alpha); _quickOptionsDialog->exec(); if (_alphaSlider->value() != alpha) _currentNote->setAlpha(_alphaSlider->value()); isShown = false; } else { qDebug() << "Problem: the sender is not a StickyNotesWidget"; } } void Dialogs::showBackgroundColorSelection() { static bool isShown = false; if (!isShown) { isShown = true; QColor newColor = QtHeWrapper::showHeSimpleColorDialog(NULL, _currentNote->backgroundColor(), true, "Pick a background color for this note"); newColor.setAlpha(_currentNote->backgroundColor().alpha()); _currentNote->setBackgroundColor(newColor); isShown = false; } } void Dialogs::showForegroundColorSelection() { static bool isShown = false; if (!isShown) { isShown = true; QColor newColor = QtHeWrapper::showHeSimpleColorDialog(NULL, _currentNote->foregroundColor(), true, "Pick a foreground color for this note"); _currentNote->setForegroundColor(newColor); isShown = false; } } void Dialogs::showFontSelection() { static bool isShown = false; if (!isShown) { isShown = true; QFont newFont = QtHeWrapper::showHeFontDialog(NULL, _currentNote->font(), "Pick a font for this note"); _currentNote->setFont(newFont); isShown = false; } } void Dialogs::showAboutDialog() { QtHeWrapper::showHeAboutDialog(NULL, "The easiest-to-use note widget for\nyour mobile computer.", "Timur Kristóf (C) 2010, Licensed under EUPL v1.1", "http://sticky-notes.garage.maemo.org/", "http://talk.maemo.org/showthread.php?t=57049", "https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=venemo%40msn%2ecom&lc=HU&item_name=Sticky%20Notes%20development%20for%20Maemo¤cy_code=EUR&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted", "sticky-notes"); }