aboutsummaryrefslogtreecommitdiffstats
path: root/src/modules/theme
diff options
context:
space:
mode:
authorGravatar Szymon Tomasz Stefanek2007-01-16 01:28:40 +0000
committerGravatar Szymon Tomasz Stefanek2007-01-16 01:28:40 +0000
commitf82d9bed8be9d4374dc219def31b6a516687db48 (patch)
treeb30fba3a355ecf15b1c6fdc6ad9e41bccee4ddb2 /src/modules/theme
parent*AUTOMATICALLY* updated KVI_SOURCES_DATE variable (diff)
downloadKVIrc-f82d9bed8be9d4374dc219def31b6a516687db48.tar.gz
KVIrc-f82d9bed8be9d4374dc219def31b6a516687db48.tar.bz2
KVIrc-f82d9bed8be9d4374dc219def31b6a516687db48.zip
First step in the Qt 4.x port
git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@174 17fca916-40b9-46aa-a4ea-0a15b648b75c
Diffstat (limited to 'src/modules/theme')
-rw-r--r--src/modules/theme/libkvitheme.cpp53
-rw-r--r--src/modules/theme/managementdialog.cpp30
-rw-r--r--src/modules/theme/managementdialog.h6
-rw-r--r--src/modules/theme/packthemedialog.cpp70
-rw-r--r--src/modules/theme/packthemedialog.h5
-rw-r--r--src/modules/theme/savethemedialog.cpp217
-rw-r--r--src/modules/theme/savethemedialog.h27
-rw-r--r--src/modules/theme/themefunctions.cpp79
-rw-r--r--src/modules/theme/themefunctions.h6
9 files changed, 400 insertions, 93 deletions
diff --git a/src/modules/theme/libkvitheme.cpp b/src/modules/theme/libkvitheme.cpp
index 12c7786ca..6c2c570e1 100644
--- a/src/modules/theme/libkvitheme.cpp
+++ b/src/modules/theme/libkvitheme.cpp
@@ -34,6 +34,8 @@
#include "kvi_mirccntrl.h"
#include "kvi_config.h"
#include "kvi_sourcesdate.h"
+#include "kvi_fileutils.h"
+#include "kvi_filedialog.h"
#include "managementdialog.h"
#include "themefunctions.h"
@@ -74,6 +76,56 @@ static bool theme_kvs_cmd_install(KviKvsModuleCommandCall * c)
}
/*
+ @doc: theme.screenshot
+ @type:
+ command
+ @title:
+ theme.screenshot
+ @short:
+ Makes a screenshot of the KVIrc window
+ @syntax:
+ theme.screenshot [file_name_path:string]
+ @description:
+ Makes a screenshot of the KVIrc main window
+ and saves it in the specified file. If [file_name_path]
+ is not specified then a save file dialog is shown.
+*/
+
+static bool theme_kvs_cmd_screenshot(KviKvsModuleCommandCall * c)
+{
+ QString szFileName;
+
+ KVSM_PARAMETERS_BEGIN(c)
+ KVSM_PARAMETER("file_name_path",KVS_PT_STRING,KVS_PF_OPTIONAL,szFileName)
+ KVSM_PARAMETERS_END(c)
+
+
+ KviFileUtils::adjustFilePath(szFileName);
+
+ QString szTmp;
+ c->enterBlockingSection();
+
+ bool bResult = KviFileDialog::askForSaveFileName(szTmp,__tr2qs_ctx("Choose a file to save the screenshot to","theme"),szFileName,"*.png");
+
+ if(!c->leaveBlockingSection())return false; // need to stop immediately
+ if(!bResult)return true;
+
+ szFileName = szTmp;
+
+ if(szFileName.isEmpty())return true; // done
+ KviFileUtils::adjustFilePath(szFileName);
+
+ QString szError;
+ if(!KviThemeFunctions::makeKVIrcScreenshot(szFileName))
+ {
+ c->error(__tr2qs_ctx("Error making screenshot","theme")); // FIXME: a nicer error ?
+ return false;
+ }
+
+ return true;
+}
+
+/*
@doc: theme.dialog
@type:
command
@@ -97,6 +149,7 @@ static bool theme_module_init(KviModule *m)
{
KVSM_REGISTER_SIMPLE_COMMAND(m,"dialog",theme_kvs_cmd_dialog);
KVSM_REGISTER_SIMPLE_COMMAND(m,"install",theme_kvs_cmd_install);
+ KVSM_REGISTER_SIMPLE_COMMAND(m,"screenshot",theme_kvs_cmd_screenshot);
QString szBuf;
m->getDefaultConfigFileName(szBuf);
diff --git a/src/modules/theme/managementdialog.cpp b/src/modules/theme/managementdialog.cpp
index 3f96ab13b..c066da522 100644
--- a/src/modules/theme/managementdialog.cpp
+++ b/src/modules/theme/managementdialog.cpp
@@ -69,6 +69,7 @@
#include "kvi_packagefile.h"
#include "kvi_fileextensions.h"
#include "kvi_filedialog.h"
+#include "kvi_dynamictooltip.h"
#include <stdlib.h> // rand & srand
@@ -116,7 +117,7 @@ KviThemeListBoxItem::~KviThemeListBoxItem()
delete m_pText;
}
-void KviThemeListBoxItem::paint ( QPainter * p )
+void KviThemeListBoxItem::paint(QPainter * p)
{
QListBoxText::paint(p);
p->drawPixmap(LVI_BORDER,LVI_BORDER, *(g_pIconManager->getBigIcon(QString(KVI_BIGICON_THEME))) );
@@ -126,7 +127,7 @@ void KviThemeListBoxItem::paint ( QPainter * p )
m_pText->draw(p,afterIcon,LVI_BORDER,QRect(afterIcon,LVI_BORDER,www,p->window().height() - (LVI_BORDER * 2)),listBox()->viewport()->colorGroup());
}
-int KviThemeListBoxItem::height ( const QListBox * lb ) const
+int KviThemeListBoxItem::height(const QListBox * lb) const
{
int iHeight = m_pText->height() + (2 * LVI_BORDER);
if(iHeight < (LVI_ICON_SIZE + (2 * LVI_BORDER)))iHeight = LVI_ICON_SIZE + (2 * LVI_BORDER);
@@ -205,6 +206,8 @@ KviThemeManagementDialog::KviThemeManagementDialog(QWidget * parent)
connect(m_pListBox,SIGNAL(selectionChanged()),this,SLOT(enableDisableButtons()));
g->addMultiCellWidget(m_pListBox,1,1,0,1);
+ KviDynamicToolTip * tip = new KviDynamicToolTip(m_pListBox);
+ connect(tip,SIGNAL(tipRequest(KviDynamicToolTip *,const QPoint &)),this,SLOT(tipRequest(KviDynamicToolTip *,const QPoint &)));
QPushButton * b = new QPushButton(__tr2qs("Close"),this);
connect(b,SIGNAL(clicked()),this,SLOT(closeClicked()));
@@ -238,6 +241,29 @@ void KviThemeManagementDialog::closeClicked()
m_pInstance = 0;
}
+void KviThemeManagementDialog::tipRequest(KviDynamicToolTip *pTip,const QPoint &pnt)
+{
+ KviThemeListBoxItem * it = (KviThemeListBoxItem *)(m_pListBox->itemAt(pnt));
+ if(!it)return;
+ KviThemeInfo * pThemeInfo = it->themeInfo();
+
+ QString szThemeDescription;
+ KviThemeFunctions::getThemeHtmlDescription(
+ szThemeDescription,
+ pThemeInfo->name(),
+ pThemeInfo->version(),
+ pThemeInfo->description(),
+ pThemeInfo->subdirectory(),
+ pThemeInfo->application(),
+ pThemeInfo->author(),
+ pThemeInfo->date(),
+ pThemeInfo->themeEngineVersion(),
+ pThemeInfo->mediumScreenshot(),
+ 0
+ );
+
+ pTip->tip(m_pListBox->itemRect(it),szThemeDescription);
+}
void KviThemeManagementDialog::display()
{
diff --git a/src/modules/theme/managementdialog.h b/src/modules/theme/managementdialog.h
index a734d557e..12762a9f9 100644
--- a/src/modules/theme/managementdialog.h
+++ b/src/modules/theme/managementdialog.h
@@ -44,6 +44,9 @@ class QLabel;
class QCheckBox;
class QMultiLineEdit;
+class KviDynamicToolTip;
+class KviStyledToolButton;
+
class KviThemeListBoxItem : public QListBoxText
{
@@ -61,8 +64,6 @@ protected:
};
-class KviStyledToolButton;
-
class KviThemeManagementDialog : public QDialog
{
Q_OBJECT
@@ -94,6 +95,7 @@ protected slots:
void applyCurrentTheme();
void enableDisableButtons();
void contextMenuRequested(QListBoxItem * item, const QPoint & pos);
+ void tipRequest(KviDynamicToolTip *pTip,const QPoint &pnt);
};
#endif //!_MANAGEMENTDIALOG_H_
diff --git a/src/modules/theme/packthemedialog.cpp b/src/modules/theme/packthemedialog.cpp
index 73352abbd..0efeb8bf5 100644
--- a/src/modules/theme/packthemedialog.cpp
+++ b/src/modules/theme/packthemedialog.cpp
@@ -39,6 +39,7 @@
#include <qmultilineedit.h>
#include <qbuffer.h>
#include <qlabel.h>
+#include <qregexp.h>
#include "kvi_options.h"
@@ -69,11 +70,17 @@ KviPackThemeDialog::KviPackThemeDialog(QWidget * pParent,KviPtrList<KviThemeInfo
QString szPackageAuthor;
QString szPackageDescription;
QString szPackageVersion;
+
+ m_szPackagePath = QDir::homeDirPath();
+ KviQString::ensureLastCharIs(m_szPackagePath,QChar(KVI_PATH_SEPARATOR_CHAR));
+
+ bool bPackagePathSet = false;
+
if(m_pThemeInfoList->count() > 1)
{
szPackageName = "MyThemes";
szPackageAuthor = __tr2qs_ctx("Your name here","theme");
- szPackageVersion = "1.0";
+ szPackageVersion = "1.0.0";
szPackageDescription = __tr2qs_ctx("Put a package description here...","theme");
} else {
if(m_pThemeInfoList->count() > 0)
@@ -83,9 +90,28 @@ KviPackThemeDialog::KviPackThemeDialog(QWidget * pParent,KviPtrList<KviThemeInfo
szPackageAuthor = pThemeInfo->author();
szPackageDescription = pThemeInfo->description();
szPackageVersion = pThemeInfo->version();
+
+ m_szPackagePath += pThemeInfo->subdirectory();
+ if(m_szPackagePath.find(QRegExp("[0-9]\\.[0-9]")) == -1)
+ {
+ m_szPackagePath += "-";
+ m_szPackagePath += szPackageVersion;
+ }
+ m_szPackagePath += ".";
+ m_szPackagePath += KVI_FILEEXTENSION_THEMEPACKAGE;
+
+ bPackagePathSet = true;
}
}
+ if(!bPackagePathSet)
+ {
+ m_szPackagePath += szPackageName;
+ m_szPackagePath += "-";
+ m_szPackagePath += szPackageVersion;
+ m_szPackagePath += ".";
+ m_szPackagePath += KVI_FILEEXTENSION_THEMEPACKAGE;
+ }
setCaption(__tr2qs_ctx("Export Theme - KVIrc","theme"));
setMinimumSize(400,350);
@@ -126,10 +152,20 @@ KviPackThemeDialog::KviPackThemeDialog(QWidget * pParent,KviPtrList<KviThemeInfo
QString szThemesDescription = "<html><body bgcolor=\"#ffffff\">";
int iIdx = 0;
+ QPixmap pixScreenshot;
+ QString szScreenshotPath;
+
for(pThemeInfo = m_pThemeInfoList->first();pThemeInfo;pThemeInfo = m_pThemeInfoList->next())
{
QString szThemeDescription;
+ if(pixScreenshot.isNull())
+ {
+ pixScreenshot = pThemeInfo->smallScreenshot();
+ if(!pixScreenshot.isNull())
+ szScreenshotPath = pThemeInfo->smallScreenshotPath();
+ }
+
KviThemeFunctions::getThemeHtmlDescription(
szThemeDescription,
pThemeInfo->name(),
@@ -139,7 +175,9 @@ KviPackThemeDialog::KviPackThemeDialog(QWidget * pParent,KviPtrList<KviThemeInfo
pThemeInfo->application(),
pThemeInfo->author(),
pThemeInfo->date(),
- pThemeInfo->themeEngineVersion()
+ pThemeInfo->themeEngineVersion(),
+ pThemeInfo->smallScreenshot(),
+ iIdx
);
if(iIdx > 0)
@@ -193,7 +231,7 @@ KviPackThemeDialog::KviPackThemeDialog(QWidget * pParent,KviPtrList<KviThemeInfo
pLabel->setText(__tr2qs_ctx("Description:","theme"));
pLayout->addWidget(pLabel,3,0);
- m_pPackageDescriptionEdit = new QMultiLineEdit(pPage);
+ m_pPackageDescriptionEdit = new QTextEdit(pPage);
m_pPackageDescriptionEdit->setText(szPackageDescription);
pLayout->addWidget(m_pPackageDescriptionEdit,3,1);
@@ -254,15 +292,6 @@ KviPackThemeDialog::KviPackThemeDialog(QWidget * pParent,KviPtrList<KviThemeInfo
pLabel->setTextFormat(Qt::RichText);
pLayout->addWidget(pLabel,0,0);
- m_szPackagePath = QDir::homeDirPath();
- KviQString::ensureLastCharIs(m_szPackagePath,QChar(KVI_PATH_SEPARATOR_CHAR));
-
- m_szPackagePath += szPackageName;
- m_szPackagePath += "-";
- m_szPackagePath += szPackageVersion;
- m_szPackagePath += ".";
- m_szPackagePath += KVI_FILEEXTENSION_THEMEPACKAGE;
-
szFilter = "*.";
szFilter += KVI_FILEEXTENSION_THEMEPACKAGE;
m_pPathSelector = new KviFileSelector(pPage,"",&m_szPackagePath,true,KviFileSelector::ChooseSaveFileName,szFilter);
@@ -281,6 +310,11 @@ KviPackThemeDialog::KviPackThemeDialog(QWidget * pParent,KviPtrList<KviThemeInfo
setNextEnabled(pPage,false);
setFinishEnabled(pPage,true);
+ if(!szScreenshotPath.isEmpty())
+ {
+ m_pImageSelector->setSelection(szScreenshotPath);
+ imageSelectionChanged(szScreenshotPath);
+ }
}
KviPackThemeDialog::~KviPackThemeDialog()
@@ -389,6 +423,18 @@ bool KviPackThemeDialog::packTheme()
f.addInfoField(szTmp,pInfo->application());
KviQString::sprintf(szTmp,"Theme%dThemeEngineVersion",iIdx);
f.addInfoField(szTmp,pInfo->themeEngineVersion());
+ QPixmap pixScreenshot = pInfo->smallScreenshot();
+ if(!pixScreenshot.isNull())
+ {
+ KviQString::sprintf(szTmp,"Theme%dScreenshot",iIdx);
+ QByteArray * pba = new QByteArray();
+ QBuffer bufferz(*pba);
+ bufferz.open(IO_WriteOnly);
+ pixScreenshot.save(&bufferz,"PNG");
+ bufferz.close();
+ f.addInfoField(szTmp,pba);
+ }
+
if(!f.addDirectory(pInfo->absoluteDirectory(),pInfo->subdirectory()))
{
szTmp = __tr2qs_ctx("Packaging failed","theme");
diff --git a/src/modules/theme/packthemedialog.h b/src/modules/theme/packthemedialog.h
index 1316369bc..b3916dab6 100644
--- a/src/modules/theme/packthemedialog.h
+++ b/src/modules/theme/packthemedialog.h
@@ -32,6 +32,7 @@
#include <qwizard.h>
class QLineEdit;
+class QTextEdit;
class QLabel;
class QMultiLineEdit;
class KviFileSelector;
@@ -51,14 +52,14 @@ protected:
QLabel * m_pImageLabel;
KviPtrList<KviThemeInfo> * m_pThemeInfoList;
QLineEdit * m_pPackageNameEdit;
- QMultiLineEdit * m_pPackageDescriptionEdit;
+ QTextEdit * m_pPackageDescriptionEdit;
QLineEdit * m_pPackageVersionEdit;
QLineEdit * m_pPackagerNameEdit;
QWidget * m_pImageSelectionPage;
protected:
virtual void accept();
-protected slots:
bool packTheme();
+protected slots:
void imageSelectionChanged(const QString &szImagePath);
};
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 <qlayout.h>
#include <qpushbutton.h>
@@ -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)
+
+KviSaveThemeDialog::KviSaveThemeDialog(QWidget * pParent)
+: QWizard(pParent)
{
- setCaption(__tr2qs_ctx("Save Current Theme","theme"));
+ setCaption(__tr2qs_ctx("Save Current Theme - KVIrc","theme"));
+ setMinimumSize(400,350);
+
+ // welcome page ==================================================================================
+ QWidget * pPage = new QWidget(this);
+ QGridLayout * pLayout = new QGridLayout(pPage,2,1,4,4);
+
+ QLabel * pLabel = new QLabel(pPage);
+ QString szText = "<p>";
+ 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 += "</p><p>";
+ szText += __tr2qs_ctx("You will be asked to provide a theme name, a description and, if you want, a screenshot.","theme");
+ szText += "</p><p>";
+ szText += __tr2qs_ctx("Hit the \"Next\" button to begin.","theme");
+ szText += "<p>";
+
+ 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);
- QGridLayout * g = new QGridLayout(this,8,2,4,4);
+ // packager informations ================================================================================
- QLabel * l;
+ pPage = new QWidget(this);
+ pLayout = new QGridLayout(pPage,5,2,4,4);
- l = new QLabel(__tr2qs_ctx("Theme name:","theme"),this);
- g->addWidget(l,0,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_pThemeNameEdit = new QLineEdit(this);
- g->addMultiCellWidget(m_pThemeNameEdit,0,0,1,2);
- connect(m_pThemeNameEdit,SIGNAL(textChanged(const QString &)),this,SLOT(themeNameChanged(const QString &)));
+ 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);
+ 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);
- l = new QLabel(__tr2qs_ctx("Version:","theme"),this);
- g->addWidget(l,1,0);
- m_pVersionEdit = new QLineEdit(this);
- g->addMultiCellWidget(m_pVersionEdit,1,1,1,2);
+ pLayout->setRowStretch(3,1);
+ pLayout->setColStretch(1,1);
+ addPage(pPage,__tr2qs_ctx("Theme Informations","theme"));
+ setBackEnabled(pPage,true);
+ setHelpEnabled(pPage,false);
+ setNextEnabled(pPage,true);
+ setFinishEnabled(pPage,false);
- l = new QLabel(__tr2qs_ctx("Author:","theme"),this);
- g->addWidget(l,2,0);
+ // screenshot/logo/icon ================================================================================
- m_pAuthorEdit = new QLineEdit(this);
- g->addMultiCellWidget(m_pAuthorEdit,2,2,1,2);
+ pPage = new QWidget(this);
+ pLayout = new QGridLayout(pPage,4,1,4,4);
- l = new QLabel(__tr2qs_ctx("Description:","theme"),this);
- g->addWidget(l,3,0);
+ 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);
- m_pDescriptionEdit = new QTextEdit(this);
- g->addMultiCellWidget(m_pDescriptionEdit,3,4,1,2);
+ 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);
- 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)));
+ 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);
- QPushButton * pb = new QPushButton(__tr2qs_ctx("Cancel","theme"),h);
- connect(pb,SIGNAL(clicked()),this,SLOT(reject()));
- pb->setIconSet(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_DISCARD)));
+ 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;
}
diff --git a/src/modules/theme/savethemedialog.h b/src/modules/theme/savethemedialog.h
index af9dd2186..5e780f750 100644
--- a/src/modules/theme/savethemedialog.h
+++ b/src/modules/theme/savethemedialog.h
@@ -26,10 +26,11 @@
#include "kvi_settings.h"
#include "kvi_list.h"
+#include "kvi_theme.h"
#include <qdialog.h>
+#include <qwizard.h>
-#include "kvi_theme.h"
class QLineEdit;
class QTextEdit;
@@ -40,21 +41,29 @@ class QMultiLineEdit;
class KviFileSelector;
-class KviSaveThemeDialog : public QDialog
+class KviSaveThemeDialog : public QWizard
{
Q_OBJECT
public:
- KviSaveThemeDialog(QWidget *par);
+ KviSaveThemeDialog(QWidget * pParent);
virtual ~KviSaveThemeDialog();
protected:
- QLineEdit * m_pAuthorEdit;
- QLineEdit * m_pThemeNameEdit;
- QLineEdit * m_pVersionEdit;
- QTextEdit * m_pDescriptionEdit;
+ QString m_szScreenshotPath;
+ KviFileSelector * m_pImageSelector;
+ QLabel * m_pImageLabel;
+ QLineEdit * m_pThemeNameEdit;
+ QTextEdit * m_pThemeDescriptionEdit;
+ QLineEdit * m_pThemeVersionEdit;
+ QLineEdit * m_pAuthorNameEdit;
+ QWidget * m_pImageSelectionPage;
QPushButton * m_pOkButton;
+protected:
+ virtual void accept();
+ bool saveTheme();
protected slots:
- void saveTheme();
- void themeNameChanged(const QString &txt);
+ void makeScreenshot();
+ void imageSelectionChanged(const QString &szImagePath);
+ //void themeNameChanged(const QString &txt);
};
diff --git a/src/modules/theme/themefunctions.cpp b/src/modules/theme/themefunctions.cpp
index d6fef4dc6..86b786f0e 100644
--- a/src/modules/theme/themefunctions.cpp
+++ b/src/modules/theme/themefunctions.cpp
@@ -33,6 +33,7 @@
#include "kvi_miscutils.h"
#include "kvi_sourcesdate.h"
#include "kvi_theme.h"
+#include "kvi_frame.h"
#include <qmime.h>
@@ -156,6 +157,11 @@ namespace KviThemeFunctions
r.getStringInfoField(szTmp,szThemeAuthor);
KviQString::sprintf(szTmp,"Theme%dThemeEngineVersion",iIdx);
r.getStringInfoField(szTmp,szThemeThemeEngineVersion);
+ KviQString::sprintf(szTmp,"Theme%dScreenshot",iIdx);
+ QPixmap pixScreenshot;
+ pByteArray = r.binaryInfoFields()->find(szTmp);
+ if(pByteArray)
+ pixScreenshot.loadFromData(*pByteArray,0,0);
if(szThemeName.isEmpty() || szThemeVersion.isEmpty() || szThemeSubdirectory.isEmpty() || szThemeThemeEngineVersion.isEmpty())
bValid = false;
@@ -173,9 +179,14 @@ namespace KviThemeFunctions
szThemeApplication,
szThemeAuthor,
szThemeDate,
- szThemeThemeEngineVersion
+ szThemeThemeEngineVersion,
+ pixScreenshot,
+ iIdx
);
+ if(iIdx > 0)
+ szDetails += "<hr>";
+
szDetails += szDetailsBuffer;
if(!bValid)
@@ -186,16 +197,12 @@ namespace KviThemeFunctions
iValidThemeCount--;
}
- if(iIdx > 0)
- szDetails += "<hr>";
-
iIdx++;
}
- szDetails += "<p><center><a href=\"theme_dialog_main\">";
+ szDetails += "<br><p><center><a href=\"theme_dialog_main\">";
szDetails += __tr2qs_ctx("Go Back to Package Data","theme");
szDetails += "</a></center></p>";
-
szDetails += "</body></html>";
if(iValidThemeCount < iThemeCount)
@@ -244,7 +251,8 @@ namespace KviThemeFunctions
&szPackageDate,
&szCreatedOn,
&szPackageApplication,
- &szWarnings
+ &szWarnings,
+ &szShowDetails
);
@@ -295,7 +303,9 @@ namespace KviThemeFunctions
const QString &szThemeApplication,
const QString &szThemeAuthor,
const QString &szThemeDate,
- const QString &szThemeThemeEngineVersion
+ const QString &szThemeThemeEngineVersion,
+ const QPixmap &pixScreenshot,
+ int iUniqueIndexInDocument
)
{
QString szAuthor = __tr2qs_ctx("Author","theme");
@@ -304,27 +314,40 @@ namespace KviThemeFunctions
QString szThemeEngineVersion = __tr2qs_ctx("Theme Engine Version","theme");
QString szSubdirectory = __tr2qs_ctx("Subdirectory","theme");
+ QString szScreenshot;
+ if(!pixScreenshot.isNull())
+ {
+ KviQString::sprintf(szScreenshot,"<p><center><img src=\"theme_shot%d\"></center></p>",iUniqueIndexInDocument);
+ QString szTmp;
+ KviQString::sprintf(szTmp,"theme_shot%d",iUniqueIndexInDocument);
+ QMimeSourceFactory::defaultFactory()->setPixmap(szTmp,pixScreenshot);
+ } else {
+ szScreenshot = "";
+ }
+
KviQString::sprintf(
szBuffer,
- "<p>" \
+ "<p><center>" \
"<h2>%Q %Q</h2>" \
- "</p>" \
- "<p>" \
+ "</center></p>" \
+ "%Q" \
+ "<p><center>" \
"<i>%Q</i>" \
- "</p>" \
- "<p>" \
+ "</center></p>" \
+ "<p><center>" \
"%Q: <b>%Q</b><br>" \
"%Q: <b>%Q</b><br>" \
- "</p>" \
- "<p>" \
+ "</center></p>" \
+ "<p><center>" \
"<font color=\"#808080\">" \
"%Q: %Q<br>" \
"%Q: %Q<br>" \
"%Q: %Q<br>" \
"</font>" \
- "</p>",
+ "</center></p>",
&szThemeName,
&szThemeVersion,
+ &szScreenshot,
&szThemeDescription,
&szAuthor,
&szThemeAuthor,
@@ -339,6 +362,30 @@ namespace KviThemeFunctions
);
}
+ bool makeKVIrcScreenshot(const QString &szSavePngFilePath,bool bMaximizeFrame)
+ {
+ if(bMaximizeFrame)
+ {
+ if(g_pFrame->isMaximized())
+ bMaximizeFrame = false;
+ }
+
+ if(bMaximizeFrame)
+ g_pFrame->showMaximized();
+
+ QPixmap pix = QPixmap::grabWidget(g_pFrame);
+ bool bResult = true;
+
+ if(pix.isNull())
+ bResult = false;
+ else {
+ if(!pix.save(szSavePngFilePath,"PNG",100))
+ bResult = false;
+ }
+ if(bMaximizeFrame)
+ g_pFrame->showNormal();
+ return bResult;
+ }
};
diff --git a/src/modules/theme/themefunctions.h b/src/modules/theme/themefunctions.h
index b628df4fb..d3b058865 100644
--- a/src/modules/theme/themefunctions.h
+++ b/src/modules/theme/themefunctions.h
@@ -28,6 +28,7 @@
#include "kvi_qstring.h"
#include <qwidget.h>
+#include <qpixmap.h>
namespace KviThemeFunctions
{
@@ -41,8 +42,11 @@ namespace KviThemeFunctions
const QString &szThemeApplication,
const QString &szThemeAuthor,
const QString &szThemeDate,
- const QString &szThemeThemeEngineVersion
+ const QString &szThemeThemeEngineVersion,
+ const QPixmap &pixScreenshot,
+ int iUniqueIndexInDocument = 0
);
+ bool makeKVIrcScreenshot(const QString &szSavePngFilePath,bool bMaximizeFrame = false);
};