From f82d9bed8be9d4374dc219def31b6a516687db48 Mon Sep 17 00:00:00 2001 From: Szymon Tomasz Stefanek Date: Tue, 16 Jan 2007 01:28:40 +0000 Subject: First step in the Qt 4.x port git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@174 17fca916-40b9-46aa-a4ea-0a15b648b75c --- src/modules/theme/savethemedialog.cpp | 221 ++++++++++++++++++++++++++-------- 1 file changed, 170 insertions(+), 51 deletions(-) (limited to 'src/modules/theme/savethemedialog.cpp') diff --git a/src/modules/theme/savethemedialog.cpp b/src/modules/theme/savethemedialog.cpp index 7a7a200c3..6e187fdb7 100644 --- a/src/modules/theme/savethemedialog.cpp +++ b/src/modules/theme/savethemedialog.cpp @@ -23,6 +23,7 @@ //============================================================================= #include "savethemedialog.h" +#include "themefunctions.h" #include #include @@ -53,87 +54,194 @@ #include "kvi_filedialog.h" #include "kvi_msgbox.h" #include "kvi_selectors.h" +#include "kvi_miscutils.h" #include "kvi_sourcesdate.h" -KviSaveThemeDialog::KviSaveThemeDialog(QWidget * par) -: QDialog(par) -{ - setCaption(__tr2qs_ctx("Save Current Theme","theme")); - - QGridLayout * g = new QGridLayout(this,8,2,4,4); - QLabel * l; +KviSaveThemeDialog::KviSaveThemeDialog(QWidget * pParent) +: QWizard(pParent) +{ + setCaption(__tr2qs_ctx("Save Current Theme - KVIrc","theme")); + setMinimumSize(400,350); - l = new QLabel(__tr2qs_ctx("Theme name:","theme"),this); - g->addWidget(l,0,0); + // welcome page ================================================================================== + QWidget * pPage = new QWidget(this); + QGridLayout * pLayout = new QGridLayout(pPage,2,1,4,4); + + QLabel * pLabel = new QLabel(pPage); + QString szText = "

"; + szText += __tr2qs_ctx("This procedure allows you to save the current theme settings to a single directory. It is useful if you want to apply other themes or play with the theme settings and later come back to this theme with a single click. It will also allow you to manually modify the theme settings and later export them to a distributable package.","theme"); + szText += "

"; + szText += __tr2qs_ctx("You will be asked to provide a theme name, a description and, if you want, a screenshot.","theme"); + szText += "

"; + szText += __tr2qs_ctx("Hit the \"Next\" button to begin.","theme"); + szText += "

"; + + pLabel->setText(szText); + pLayout->addWidget(pLabel,0,0); + pLayout->setRowStretch(1,1); + + addPage(pPage,__tr2qs_ctx("Welcome","theme")); + setBackEnabled(pPage,false); + setNextEnabled(pPage,true); + setHelpEnabled(pPage,false); + setFinishEnabled(pPage,false); - m_pThemeNameEdit = new QLineEdit(this); - g->addMultiCellWidget(m_pThemeNameEdit,0,0,1,2); - connect(m_pThemeNameEdit,SIGNAL(textChanged(const QString &)),this,SLOT(themeNameChanged(const QString &))); + // packager informations ================================================================================ + pPage = new QWidget(this); + pLayout = new QGridLayout(pPage,5,2,4,4); - l = new QLabel(__tr2qs_ctx("Version:","theme"),this); - g->addWidget(l,1,0); + pLabel = new QLabel(pPage); + pLabel->setText(__tr2qs_ctx("Here you need to provide informations about you (the author) and a short description of the theme you're creating.","theme")); + pLabel->setTextFormat(Qt::RichText); + pLayout->addMultiCellWidget(pLabel,0,0,0,1); + + pLabel = new QLabel(pPage); + pLabel->setText(__tr2qs_ctx("Theme Name:","theme")); + pLayout->addWidget(pLabel,1,0); + + m_pThemeNameEdit = new QLineEdit(pPage); + //m_pThemeNameEdit->setText(szThemeName); + pLayout->addWidget(m_pThemeNameEdit,1,1); - m_pVersionEdit = new QLineEdit(this); - g->addMultiCellWidget(m_pVersionEdit,1,1,1,2); + pLabel = new QLabel(pPage); + pLabel->setText(__tr2qs_ctx("Version:","theme")); + pLayout->addWidget(pLabel,2,0); + + m_pThemeVersionEdit = new QLineEdit(pPage); + //m_pThemeVersionEdit->setText(szThemeVersion); + pLayout->addWidget(m_pThemeVersionEdit,2,1); + pLabel = new QLabel(pPage); + pLabel->setText(__tr2qs_ctx("Description:","theme")); + pLayout->addWidget(pLabel,3,0); + + m_pThemeDescriptionEdit = new QTextEdit(pPage); + //m_pThemeDescriptionEdit->setText(szThemeDescription); + pLayout->addWidget(m_pThemeDescriptionEdit,3,1); - l = new QLabel(__tr2qs_ctx("Author:","theme"),this); - g->addWidget(l,2,0); + pLabel = new QLabel(pPage); + pLabel->setText(__tr2qs_ctx("Theme Author:","theme")); + pLayout->addWidget(pLabel,4,0); + + m_pAuthorNameEdit = new QLineEdit(pPage); + //m_pAuthorNameEdit->setText(szThemeAuthor); + pLayout->addWidget(m_pAuthorNameEdit,4,1); - m_pAuthorEdit = new QLineEdit(this); - g->addMultiCellWidget(m_pAuthorEdit,2,2,1,2); - l = new QLabel(__tr2qs_ctx("Description:","theme"),this); - g->addWidget(l,3,0); + pLayout->setRowStretch(3,1); + pLayout->setColStretch(1,1); - m_pDescriptionEdit = new QTextEdit(this); - g->addMultiCellWidget(m_pDescriptionEdit,3,4,1,2); + addPage(pPage,__tr2qs_ctx("Theme Informations","theme")); + setBackEnabled(pPage,true); + setHelpEnabled(pPage,false); + setNextEnabled(pPage,true); + setFinishEnabled(pPage,false); - QHBox * h = new QHBox(this); - h->setSpacing(7); - g->addWidget(h,7,2); - m_pOkButton = new QPushButton(__tr2qs_ctx("OK","theme"),h); - m_pOkButton->setEnabled(false); - connect(m_pOkButton,SIGNAL(clicked()),this,SLOT(saveTheme())); - m_pOkButton->setIconSet(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_ACCEPT))); + // screenshot/logo/icon ================================================================================ - QPushButton * pb = new QPushButton(__tr2qs_ctx("Cancel","theme"),h); - connect(pb,SIGNAL(clicked()),this,SLOT(reject())); - pb->setIconSet(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_DISCARD))); + pPage = new QWidget(this); + pLayout = new QGridLayout(pPage,4,1,4,4); + pLabel = new QLabel(pPage); + pLabel->setText(__tr2qs_ctx("Here you can either choose a screenshot image from disk or make one now. The screenshot will be displayed in the tooltips of the theme management dialog and will be also visible in the package installation dialog if you will export the theme to a distributable package.","theme")); + pLabel->setTextFormat(Qt::RichText); + pLayout->addWidget(pLabel,0,0); + + m_pImageLabel = new QLabel(pPage); + m_pImageLabel->setFrameStyle(QFrame::Sunken | QFrame::Panel); + m_pImageLabel->setMinimumSize(300,225); + m_pImageLabel->setAlignment(Qt::AlignCenter | Qt::AlignVCenter); + pLayout->addWidget(m_pImageLabel,1,0); + + QString szFilter = "*.png *.jpg *.xpm"; + m_pImageSelector = new KviFileSelector(pPage,"",&m_szScreenshotPath,true,0,szFilter); + connect(m_pImageSelector,SIGNAL(selectionChanged(const QString &)),this,SLOT(imageSelectionChanged(const QString &))); + pLayout->addWidget(m_pImageSelector,2,0); + + QPushButton * pButton = new QPushButton(pPage); + pButton->setText(__tr2qs_ctx("Make Screenshot Now","theme")); + connect(pButton,SIGNAL(clicked()),this,SLOT(makeScreenshot())); + pLayout->addWidget(pButton,3,0); + + pLayout->setRowStretch(1,1); + + m_pImageSelectionPage = pPage; + addPage(pPage,__tr2qs_ctx("Screenshot","theme")); + setBackEnabled(pPage,true); + setHelpEnabled(pPage,false); + setNextEnabled(pPage,true); + setFinishEnabled(pPage,true); } KviSaveThemeDialog::~KviSaveThemeDialog() { +} + +void KviSaveThemeDialog::imageSelectionChanged(const QString &szImagePath) +{ + QImage pix(szImagePath); + if(!pix.isNull()) + { + QPixmap out; + if(pix.width() > 300 || pix.height() > 225) + out.convertFromImage(pix.smoothScale(300,225,QImage::ScaleMin)); + else + out.convertFromImage(pix); + m_pImageLabel->setPixmap(out); + return; + } + QMessageBox::critical(this,__tr2qs_ctx("Save Current Theme - KVIrc","theme"),__tr2qs_ctx("Failed to load the selected image","theme"), + QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton); + + m_pImageSelector->setSelection(""); + m_pImageLabel->setPixmap(QPixmap()); } -void KviSaveThemeDialog::themeNameChanged(const QString &txt) + +void KviSaveThemeDialog::accept() { - m_pOkButton->setEnabled(!txt.isEmpty()); + if(!saveTheme())return; + QWizard::accept(); } -void KviSaveThemeDialog::saveTheme() +void KviSaveThemeDialog::makeScreenshot() { + QString szFileName; + g_pApp->getTmpFileName(szFileName,"screenshot.png"); + if(!KviThemeFunctions::makeKVIrcScreenshot(szFileName)) + { + QMessageBox::critical(this,__tr2qs_ctx("Acquire Screenshot - KVIrc","theme"),__tr2qs_ctx("Failed to make screenshot","theme"), + QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton); + return; + } + m_pImageSelector->setSelection(szFileName); + imageSelectionChanged(szFileName); +} + +bool KviSaveThemeDialog::saveTheme() +{ + m_pImageSelector->commit(); + KviThemeInfo sto; sto.setName(m_pThemeNameEdit->text()); if(sto.name().isEmpty()) { - QMessageBox::critical(this,__tr2qs_ctx("Save Theme - KVIrc","theme"),__tr2qs_ctx("You must choose a theme name!","theme"),QMessageBox::Ok, + QMessageBox::critical(this,__tr2qs_ctx("Save Current Theme - KVIrc","theme"),__tr2qs_ctx("You must choose a theme name!","theme"),QMessageBox::Ok, QMessageBox::NoButton,QMessageBox::NoButton); - return; + return false; } - sto.setAuthor(m_pAuthorEdit->text()); - sto.setDescription(m_pDescriptionEdit->text()); + sto.setAuthor(m_pAuthorNameEdit->text()); + sto.setDescription(m_pThemeDescriptionEdit->text()); sto.setDate(QDateTime::currentDateTime().toString()); - sto.setVersion(m_pVersionEdit->text()); + sto.setVersion(m_pThemeVersionEdit->text()); sto.setApplication("KVIrc " KVI_VERSION "." KVI_SOURCES_DATE); - + if(sto.version().isEmpty())sto.setVersion("1.0.0"); QString szSubdir = sto.name() + QString("-") + sto.version(); @@ -144,23 +252,34 @@ void KviSaveThemeDialog::saveTheme() g_pApp->getLocalKvircDirectory(szAbsDir,KviApp::Themes,sto.subdirectory(),true); if(!KviFileUtils::makeDir(szAbsDir)) { - QMessageBox::critical(this,__tr2qs_ctx("Save Theme - KVIrc","theme"),__tr2qs_ctx("Unable to create theme directory.","theme"), + QMessageBox::critical(this,__tr2qs_ctx("Save Current Theme - KVIrc","theme"),__tr2qs_ctx("Unable to create theme directory.","theme"), QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton); - return; + return false; } - + sto.setAbsoluteDirectory(szAbsDir); - + if(!KviTheme::save(sto)) { QString szMsg2; QString szErr = sto.lastError(); KviQString::sprintf(szMsg2,__tr2qs_ctx("Unable to save theme: %Q","theme"),&szErr); - QMessageBox::critical(this,__tr2qs_ctx("Save Theme - KVIrc","theme"),szMsg2, + QMessageBox::critical(this,__tr2qs_ctx("Save Current Theme - KVIrc","theme"),szMsg2, QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton); - return; + return false; + } + // write down the screenshot, if needed + + if(!m_szScreenshotPath.isEmpty()) + { + if(!KviTheme::saveScreenshots(sto,m_szScreenshotPath)) + { + QMessageBox::critical(this,__tr2qs_ctx("Save Current Theme - KVIrc","theme"),__tr2qs_ctx("Failed to load the selected screenshot image: please fix it","theme"), + QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton); + showPage(m_pImageSelectionPage); + return false; + } } - // write down the images QString szMsg = __tr2qs_ctx("Theme saved successfully to ","theme"); szMsg += sto.absoluteDirectory(); @@ -168,6 +287,6 @@ void KviSaveThemeDialog::saveTheme() QMessageBox::information(this,__tr2qs_ctx("Save Theme - KVIrc","theme"),szMsg,QMessageBox::Ok, QMessageBox::NoButton,QMessageBox::NoButton); - accept(); + return true; } -- cgit v1.3.1-10-gc9f91