aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Fabio Bas2010-04-05 20:02:22 +0000
committerGravatar Fabio Bas2010-04-05 20:02:22 +0000
commit6b80ba5098604bf9198b08bb51d2dc6327ca91d6 (patch)
tree511cc3ef0c3b559b2f257f1bc9a23795ead1275b /src
parentfix for #755 (diff)
downloadKVIrc-6b80ba5098604bf9198b08bb51d2dc6327ca91d6.tar.gz
KVIrc-6b80ba5098604bf9198b08bb51d2dc6327ca91d6.tar.bz2
KVIrc-6b80ba5098604bf9198b08bb51d2dc6327ca91d6.zip
fix for #756, implemented #757
git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@4240 17fca916-40b9-46aa-a4ea-0a15b648b75c
Diffstat (limited to 'src')
-rw-r--r--src/modules/tip/CMakeLists.txt4
-rw-r--r--src/modules/tip/libkvitip.cpp162
-rw-r--r--src/modules/tip/libkvitip.h15
3 files changed, 86 insertions, 95 deletions
diff --git a/src/modules/tip/CMakeLists.txt b/src/modules/tip/CMakeLists.txt
index fba083b7b..a4cf080ad 100644
--- a/src/modules/tip/CMakeLists.txt
+++ b/src/modules/tip/CMakeLists.txt
@@ -9,6 +9,7 @@ SET(kvitip_SRCS
)
FILE(GLOB tips "*.kvc")
+FILE(GLOB pics "*.png")
# After this call, files will be moc'ed to moc_kvi_*.cpp
QT4_WRAP_CPP(kvitip_MOC_SRCS ${kvitip_MOC_HDRS})
@@ -20,10 +21,13 @@ INCLUDE(${CMAKE_SOURCE_DIR}/cmake/module.rules.txt)
IF(UNIX)
IF(APPLE)
INSTALL(FILES ${tips} DESTINATION ${CMAKE_INSTALL_PREFIX}/Contents/Resources/config/modules/)
+ INSTALL(FILES ${pics} DESTINATION ${CMAKE_INSTALL_PREFIX}/Contents/Resources/pics/)
ELSE()
# Assume linux
INSTALL(FILES ${tips} DESTINATION ${CMAKE_INSTALL_PREFIX}/share/kvirc/${VERSION_BRANCH}/config/modules/)
+ INSTALL(FILES ${pics} DESTINATION ${CMAKE_INSTALL_PREFIX}/share/kvirc/${VERSION_BRANCH}/pics/)
ENDIF()
ELSEIF(WIN32)
INSTALL(FILES ${tips} DESTINATION ${CMAKE_INSTALL_PREFIX}/config/modules/)
+ INSTALL(FILES ${pics} DESTINATION ${CMAKE_INSTALL_PREFIX}/pics/)
ENDIF() \ No newline at end of file
diff --git a/src/modules/tip/libkvitip.cpp b/src/modules/tip/libkvitip.cpp
index e444c10cd..5f3e6a65f 100644
--- a/src/modules/tip/libkvitip.cpp
+++ b/src/modules/tip/libkvitip.cpp
@@ -33,117 +33,78 @@
#include <QPushButton>
#include <QFont>
-#include <QTextCodec>
#include <QPainter>
#include <QDesktopWidget>
#include <QCloseEvent>
-#include <QTextDocument>
-
KviTipWindow * g_pTipWindow = 0;
-#define KVI_TIP_WINDOW_HEIGHT 200
-#define KVI_TIP_WINDOW_WIDTH 500
-#define KVI_TIP_WINDOW_BUTTON_WIDTH 80
-#define KVI_TIP_WINDOW_BUTTON_HEIGHT 30
-#define KVI_TIP_WINDOW_BORDER 5
-#define KVI_TIP_WINDOW_DOUBLE_BORDER 10
-#define KVI_TIP_WINDOW_SPACING 2
-
-
KviTipFrame::KviTipFrame(QWidget * par)
: QFrame(par)
{
- m_pText=0;
QString buffer;
+ m_pLabel1 = new QLabel(this);
+ m_pLabel2 = new QLabel(this);
g_pApp->findImage(buffer,"kvi_tip.png");
- m_pTipPixmap = new QPixmap(buffer);
+ m_pLabel1->setPixmap(buffer);
+ setStyleSheet("QFrame { background: black; }");
+ m_pLabel1->setStyleSheet("QLabel { background: black; }");
+ m_pLabel2->setStyleSheet("QLabel { background: black; color: white; }");
+ m_pLabel2->setWordWrap(true);
+ m_pLabel2->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum);
setFrameStyle(QFrame::Sunken | QFrame::WinPanel);
+ QGridLayout *layout = new QGridLayout(this);
+ layout->addWidget(m_pLabel1,0,0,1,1);
+ layout->addWidget(m_pLabel2,0,1,1,1);
+ layout->setColumnStretch(1,1);
+ setLayout(layout);
}
KviTipFrame::~KviTipFrame()
{
- if (m_pText) delete m_pText;
- delete m_pTipPixmap;
}
void KviTipFrame::setText(const QString &text)
{
- QString szText= "<center><font color=\"#FFFFFF\">";
+ QString szText= "<center>";
szText += text;
- szText += "</font></center>";
- if (m_pText) delete m_pText;
- m_pText = new QTextDocument();
- QFont f = font();
- f.setStyleHint(QFont::SansSerif);
- f.setPointSize(12);
- m_pText->setHtml(szText);
- m_pText->setDefaultFont(f);
+ szText += "</center>";
+ m_pLabel2->setText(szText);
update();
}
-void KviTipFrame::paintEvent(QPaintEvent *)
-{
- QPainter p(this);
- SET_ANTI_ALIASING(p);
- p.fillRect(contentsRect(),QColor(0,0,0));
- p.drawPixmap(5,(height() - m_pTipPixmap->height()) / 2,*m_pTipPixmap);
-
- int www = width() - m_pTipPixmap->width();
- p.translate(m_pTipPixmap->width(),5);
- m_pText->setPageSize(QSizeF(www,height() /2));
- m_pText->drawContents(&p);
-
-}
-
KviTipWindow::KviTipWindow()
{
setObjectName("kvirc_tip_window");
- /*,WStyle_Customize | WStyle_Title | WStyle_DialogBorder | WStyle_StaysOnTop*/
m_pConfig = 0;
m_pTipFrame = new KviTipFrame(this);
- m_pTipFrame->setGeometry(
- KVI_TIP_WINDOW_BORDER,
- KVI_TIP_WINDOW_BORDER,
- KVI_TIP_WINDOW_WIDTH - KVI_TIP_WINDOW_DOUBLE_BORDER,
- KVI_TIP_WINDOW_HEIGHT - (KVI_TIP_WINDOW_DOUBLE_BORDER + KVI_TIP_WINDOW_BUTTON_HEIGHT + KVI_TIP_WINDOW_SPACING));
+ QPushButton * pb = new QPushButton("<<",this);
+ connect(pb,SIGNAL(clicked()),this,SLOT(prevTip()));
- QPushButton * pb = new QPushButton(">>",this);
- pb->setGeometry(
- KVI_TIP_WINDOW_WIDTH - ((KVI_TIP_WINDOW_BUTTON_WIDTH * 2)+ KVI_TIP_WINDOW_BORDER + KVI_TIP_WINDOW_SPACING),
- KVI_TIP_WINDOW_HEIGHT - (KVI_TIP_WINDOW_BUTTON_HEIGHT + KVI_TIP_WINDOW_BORDER),
- KVI_TIP_WINDOW_BUTTON_WIDTH,
- KVI_TIP_WINDOW_BUTTON_HEIGHT
- );
- connect(pb,SIGNAL(clicked()),this,SLOT(nextTip()));
+ QPushButton * pb2 = new QPushButton(">>",this);
+ connect(pb2,SIGNAL(clicked()),this,SLOT(nextTip()));
- pb = new QPushButton(__tr2qs("Close"),this);
- pb->setGeometry(
- KVI_TIP_WINDOW_WIDTH - (KVI_TIP_WINDOW_BUTTON_WIDTH + KVI_TIP_WINDOW_BORDER),
- KVI_TIP_WINDOW_HEIGHT - (KVI_TIP_WINDOW_BUTTON_HEIGHT + KVI_TIP_WINDOW_BORDER),
- KVI_TIP_WINDOW_BUTTON_WIDTH,
- KVI_TIP_WINDOW_BUTTON_HEIGHT
- );
- connect(pb,SIGNAL(clicked()),this,SLOT(close()));
- pb->setDefault(true);
+ QPushButton * pb3 = new QPushButton(__tr2qs("Close"),this);
+ connect(pb3,SIGNAL(clicked()),this,SLOT(close()));
+ pb3->setDefault(true);
m_pShowAtStartupCheck = new QCheckBox(__tr2qs("Show at startup"),this);
m_pShowAtStartupCheck->setChecked(KVI_OPTION_BOOL(KviOption_boolShowTipAtStartup));
- m_pShowAtStartupCheck->setGeometry(
- KVI_TIP_WINDOW_BORDER,
- KVI_TIP_WINDOW_HEIGHT - (KVI_TIP_WINDOW_BUTTON_HEIGHT + KVI_TIP_WINDOW_BORDER),
- KVI_TIP_WINDOW_WIDTH - ((KVI_TIP_WINDOW_BORDER + KVI_TIP_WINDOW_BUTTON_WIDTH + KVI_TIP_WINDOW_SPACING) * 2),
- KVI_TIP_WINDOW_BUTTON_HEIGHT
- );
-
- setFixedSize(KVI_TIP_WINDOW_WIDTH,KVI_TIP_WINDOW_HEIGHT);
setWindowIcon(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_IDEA)));
setWindowTitle(__tr2qs("Did you know..."));
- pb->setFocus();
+ QGridLayout *layout = new QGridLayout(this);
+ layout->addWidget(m_pTipFrame,0,0,1,5);
+ layout->addWidget(m_pShowAtStartupCheck,1,0,1,1);
+ layout->addWidget(pb,1,2,1,1);
+ layout->addWidget(pb2,1,3,1,1);
+ layout->addWidget(pb3,1,4,1,1);
+ setLayout(layout);
+
+ pb3->setFocus();
}
@@ -153,6 +114,12 @@ KviTipWindow::~KviTipWindow()
if(m_pConfig)closeConfig();
}
+void KviTipWindow::showEvent(QShowEvent *)
+{
+ QRect rect = g_pApp->desktop()->screenGeometry(g_pApp->desktop()->primaryScreen());
+ move((rect.width() - width())/2,(rect.height() - height())/2);
+}
+
bool KviTipWindow::openConfig(QString filename,bool bEnsureExists)
{
if(m_pConfig)closeConfig();
@@ -203,29 +170,56 @@ void KviTipWindow::nextTip()
}
unsigned int uNumTips = m_pConfig->readUIntEntry("uNumTips",0);
- unsigned int uNextTip = m_pConfig->readUIntEntry("uNextTip",0);
+ unsigned int uCurTip = m_pConfig->readUIntEntry("uCurTip",0);
+ uCurTip++;
+ if(uCurTip >= uNumTips)uCurTip = 0;
- KviStr tmp(KviStr::Format,"%u",uNextTip);
+ KviStr tmp(KviStr::Format,"%u",uCurTip);
QString szTip = m_pConfig->readEntry(tmp.ptr(),__tr2qs("<b>Can't find any tip... :(</b>"));
//qDebug("REDECODED=%s",szTip.toUtf8().data());
- uNextTip++;
- if(uNextTip >= uNumTips)uNextTip = 0;
- m_pConfig->writeEntry("uNextTip",uNextTip);
+ m_pConfig->writeEntry("uCurTip",uCurTip);
m_pTipFrame->setText(szTip);
}
-void KviTipWindow::showEvent(QShowEvent *e)
+void KviTipWindow::prevTip()
{
- resize(KVI_TIP_WINDOW_WIDTH,KVI_TIP_WINDOW_HEIGHT);
+ if(!m_pConfig)
+ {
+ KviStr szLocale = KviLocale::localeName();
+ KviStr szFile;
+ szFile.sprintf("libkvitip_%s.kvc",szLocale.ptr());
+ if(!openConfig(szFile.ptr(),true))
+ {
+ szLocale.cutFromFirst('.');
+ szLocale.cutFromFirst('_');
+ szLocale.cutFromFirst('@');
+ szFile.sprintf("libkvitip_%s.kvc",szLocale.ptr());
+ if(!openConfig(szFile.ptr(),true))
+ {
+ openConfig("libkvitip.kvc",false);
+ }
+ }
+ }
- QRect rect = g_pApp->desktop()->screenGeometry(g_pApp->desktop()->primaryScreen());
- move((rect.width() - KVI_TIP_WINDOW_WIDTH)/2,(rect.height() - KVI_TIP_WINDOW_HEIGHT)/2);
+ unsigned int uNumTips = m_pConfig->readUIntEntry("uNumTips",0);
+ unsigned int uCurTip = m_pConfig->readUIntEntry("uCurTip",0);
+
+
+ if(uCurTip == 0)uCurTip = uNumTips-1;
+ else uCurTip--;
+
+ KviStr tmp(KviStr::Format,"%u",uCurTip);
+ QString szTip = m_pConfig->readEntry(tmp.ptr(),__tr2qs("<b>Can't find any tip... :(</b>"));
- QWidget::showEvent(e);
+ //qDebug("REDECODED=%s",szTip.toUtf8().data());
+
+ m_pConfig->writeEntry("uCurTip",uCurTip);
+
+ m_pTipFrame->setText(szTip);
}
void KviTipWindow::closeEvent(QCloseEvent *e)
@@ -265,12 +259,8 @@ static bool tip_kvs_cmd_open(KviKvsModuleCommandCall * c)
if(!g_pTipWindow)g_pTipWindow = new KviTipWindow();
bool error=false;
- if (!szTipfilename.isEmpty()){
- debug("Loading config tip");
+ if (!szTipfilename.isEmpty())
error=g_pTipWindow->openConfig(szTipfilename);
- if (!error) debug ("Not opened");
- else debug("Opened");
- }
g_pTipWindow->nextTip();
g_pTipWindow->show();
return true;
diff --git a/src/modules/tip/libkvitip.h b/src/modules/tip/libkvitip.h
index b1d432d4b..2190780a3 100644
--- a/src/modules/tip/libkvitip.h
+++ b/src/modules/tip/libkvitip.h
@@ -29,10 +29,8 @@
#include <QWidget>
#include <QFrame>
-#include <QPixmap>
+#include <QLabel>
#include <QCheckBox>
-#include <QTextDocument>
-
class KviTipFrame : public QFrame
{
@@ -40,11 +38,9 @@ class KviTipFrame : public QFrame
public:
KviTipFrame(QWidget * par);
~KviTipFrame();
-protected:
- QTextDocument *m_pText;
- QPixmap * m_pTipPixmap;
-protected:
- virtual void paintEvent(QPaintEvent * );
+private:
+ QLabel *m_pLabel1;
+ QLabel *m_pLabel2;
public:
void setText(const QString &text);
};
@@ -61,13 +57,14 @@ protected:
KviConfig * m_pConfig;
QString m_szConfigFileName; // no path!
protected:
- virtual void showEvent(QShowEvent *e);
virtual void closeEvent(QCloseEvent *e);
+ virtual void showEvent(QShowEvent *e);
public:
bool openConfig(QString filename,bool bEnsureExists = true);
void closeConfig();
public slots:
void nextTip();
+ void prevTip();
};
#endif //_LIBKVITIP_H_