26 #include <tqcheckbox.h>
31 #include <tqpushbutton.h>
33 #include <tqtextstream.h>
36 #include <tdeaboutdata.h>
37 #include <tdeapplication.h>
38 #include <tdeconfig.h>
40 #include <tdeglobal.h>
41 #include <kiconloader.h>
43 #include <kpushbutton.h>
44 #include <kseparator.h>
45 #include <kstandarddirs.h>
46 #include <kstdguiitem.h>
47 #include <ktextbrowser.h>
48 #include <kiconeffect.h>
49 #include <tdeglobalsettings.h>
60 TQString tipFile = _tipFile;
61 if (tipFile.isEmpty())
67 mCurrent = kapp->random() % mTips.count();
73 if ( tipsFiles.isEmpty() || ( ( tipsFiles.count() == 1 ) && tipsFiles.first().isEmpty() ) )
79 for (TQStringList::ConstIterator it = tipsFiles.begin(); it != tipsFiles.end(); ++it)
83 mCurrent = kapp->random() % mTips.count();
87 void KTipDatabase::loadTips(
const TQString &tipFile)
96 void KTipDatabase::addTips(
const TQString& tipFile )
98 TQString fileName =
locate(
"data", tipFile);
100 if (fileName.isEmpty())
102 kdDebug() <<
"KTipDatabase::addTips: can't find '" << tipFile <<
"' in standard dirs" <<
endl;
106 TQFile file(fileName);
107 if (!file.open(IO_ReadOnly))
109 kdDebug() <<
"KTipDatabase::addTips: can't open '" << fileName <<
"' for reading" <<
endl;
113 TQByteArray data = file.readAll();
114 TQString content = TQString::fromUtf8(data.data(), data.size());
115 const TQRegExp rx(
"\\n+");
118 while ((pos = content.find(
"<html>", pos + 1,
false)) != -1)
122 TQString
tip = content
123 .mid(pos + 6, content.find(
"</html>", pos,
false) - pos - 6)
125 if (!
tip.endsWith(
"\n"))
127 if (
tip.startsWith(
"\n"))
131 kdDebug() <<
"Empty tip found! Skipping! " << pos <<
endl;
146 if (mCurrent >= (
int) mTips.count())
157 mCurrent = mTips.count() - 1;
164 return TQString::null;
165 return mTips[mCurrent];
178 bool isTipDialog = (parent);
184 mBlendedColor.hsv(&h,&s,&v);
185 mBlendedColor.setHsv(h,
int(s*(71/76.0)),
int(v*(67/93.0)));
189 img = TQImage(
locate(
"data",
"tdewizard/pics/wizard_small.png"));
192 TQRgb colPixel( img.pixel(0,0) );
194 mBlendedColor = TQColor(tqRed(colPixel),tqGreen(colPixel),tqBlue(colPixel));
198 mBaseColor.hsv(&h,&s,&v);
199 mBaseColor.setHsv(h,
int(s*(10/6.0)),
int(v*(93/99.0)));
216 TQHBoxLayout *pl =
new TQHBoxLayout(vbox, 0, 0);
218 TQLabel *bulb =
new TQLabel(
this);
219 bulb->setPixmap(
locate(
"data",
"tdeui/pics/ktip-bulb.png"));
222 TQLabel *titlePane =
new TQLabel(
this);
223 titlePane->setBackgroundPixmap(
locate(
"data",
"tdeui/pics/ktip-background.png"));
224 titlePane->setText(i18n(
"Did you know...?\n"));
226 titlePane->setAlignment(TQLabel::AlignCenter);
227 pl->addWidget(titlePane, 100);
230 TQHBox *hbox =
new TQHBox(
this);
232 hbox->setFrameStyle(TQFrame::Panel | TQFrame::Sunken);
233 vbox->addWidget(hbox);
235 TQHBox *tl =
new TQHBox(hbox);
237 tl->setBackgroundColor(mBlendedColor);
239 TQHBox *topLeft =
new TQHBox(tl);
240 topLeft->setMargin(15);
241 topLeft->setBackgroundColor(mBaseColor);
245 mTipText->setWrapPolicy( TQTextEdit::AtWordOrDocumentBoundary );
246 mTipText->mimeSourceFactory()->addFilePath(
247 TDEGlobal::dirs()->findResourceDir(
"data",
"tdewizard/pics")+
"tdewizard/pics/");
248 mTipText->setFrameStyle(TQFrame::NoFrame | TQFrame::Plain);
249 mTipText->setHScrollBarMode(TQScrollView::AlwaysOff);
250 mTipText->setLinkUnderline(
false);
252 TQStyleSheet *sheet = mTipText->styleSheet();
253 TQStyleSheetItem *item = sheet->item(
"a");
254 item->setFontWeight(TQFont::Bold);
255 mTipText->setStyleSheet(sheet);
256 TQPalette pal = mTipText->palette();
257 pal.setColor( TQPalette::Active, TQColorGroup::Link, mBlendedColor );
258 pal.setColor( TQPalette::Inactive, TQColorGroup::Link, mBlendedColor );
259 mTipText->setPalette(pal);
262 TQStringList::Iterator it;
263 for (it = icons.begin(); it != icons.end(); ++it)
264 mTipText->mimeSourceFactory()->addFilePath(*it);
268 TQLabel *l =
new TQLabel(hbox);
270 l->setBackgroundColor(mBlendedColor);
271 l->setAlignment(TQt::AlignRight | TQt::AlignBottom);
278 move(rect.x() + (rect.width() - sh.width())/2,
279 rect.y() + (rect.height() - sh.height())/2);
283 vbox->addWidget(sep);
285 TQHBoxLayout *hbox2 =
new TQHBoxLayout(vbox, 4);
287 mTipOnStart =
new TQCheckBox(i18n(
"&Show tips on startup"),
this);
288 hbox2->addWidget(mTipOnStart, 1);
291 KStdGuiItem::UseRTL ),
this );
292 prev->
setText( i18n(
"&Previous") );
293 hbox2->addWidget(prev);
296 KStdGuiItem::UseRTL ),
this );
297 next->setText( i18n(
"Opposite to Previous",
"&Next") );
298 hbox2->addWidget(next);
301 ok->setDefault(
true);
302 hbox2->addWidget(ok);
305 mTipOnStart->setChecked(config.
readBoolEntry(
"RunOnStart",
true));
307 connect(next, TQ_SIGNAL(clicked()),
this, TQ_SLOT(nextTip()));
308 connect(prev, TQ_SIGNAL(clicked()),
this, TQ_SLOT(prevTip()));
309 connect(ok, TQ_SIGNAL(clicked()),
this, TQ_SLOT(accept()));
310 connect(mTipOnStart, TQ_SIGNAL(toggled(
bool)),
this, TQ_SLOT(showOnStart(
bool)));
317 KTipDialog::~KTipDialog()
319 if( mInstance==
this )
325 showTip(kapp->mainWidget(), tipFile, force);
337 const bool runOnStart = configGroup.
readBoolEntry(
"RunOnStart",
true);
344 bool hasLastShown = configGroup.
hasKey(
"TipLastShown");
347 const int oneDay = 24*60*60;
350 if (lastShown.secsTo(TQDateTime::currentDateTime()) < (oneDay + (kapp->random() % (10*oneDay))))
353 configGroup.
writeEntry(
"TipLastShown", TQDateTime::currentDateTime());
354 kapp->config()->sync();
364 mInstance->mTipOnStart->setChecked(runOnStart);
370 static TQString fixTip(TQString tip)
372 TQRegExp iconRegExp(
"<img src=\"(.*)\">");
373 iconRegExp.setMinimal(
true);
374 if (iconRegExp.search(tip)>-1) {
375 TQString iconName = iconRegExp.cap(1);
376 if (!iconName.isEmpty())
378 tip.replace(
"crystalsvg",
"hicolor");
384 void KTipDialog::prevTip()
387 TQString currentTip = TQString::fromLatin1(
388 "<qt text=\"%1\" bgcolor=\"%2\">%3</qt>")
389 .arg(mTextColor.name())
390 .arg(mBaseColor.name())
391 .arg(i18n(mDatabase->
tip().utf8()));
394 currentTip = fixTip(currentTip);
395 mTipText->setText(currentTip);
396 mTipText->setContentsPos(0, 0);
399 void KTipDialog::nextTip()
402 TQString currentTip = TQString::fromLatin1(
403 "<qt text=\"%1\" bgcolor=\"%2\">%3</qt>")
404 .arg(mTextColor.name())
405 .arg(mBaseColor.name())
406 .arg(i18n(mDatabase->
tip().utf8()));
409 currentTip = fixTip(currentTip);
410 mTipText->setText(currentTip);
411 mTipText->setContentsPos(0, 0);
414 void KTipDialog::showOnStart(
bool on)
426 bool KTipDialog::eventFilter(TQObject *o, TQEvent *e)
428 if (o == mTipText && e->type()== TQEvent::KeyPress &&
429 (((TQKeyEvent *)e)->key() == Key_Return ||
430 ((TQKeyEvent *)e)->key() == Key_Space ))
439 return TQWidget::eventFilter( o, e );
442 void KTipDialog::virtual_hook(
int id,
void* data )
444 KDialog::virtual_hook(
id, data );
Dialog with extended non-modal support and methods for KDE standard compliance.
static int marginHint()
Return the number of pixels you shall use between a dialog edge and the outermost widget(s) according...
static int spacingHint()
Return the number of pixels you shall use between widgets inside a dialog according to the KDE standa...
virtual void setCaption(const TQString &caption)
Make a KDE compliant caption.
Standard horizontal or vertical separator.
static KGuiItem back(BidiMode useBidi=IgnoreRTL)
Return a GUI item for a 'back' action, like Konqueror's back button.
static KGuiItem forward(BidiMode useBidi=IgnoreRTL)
Return a GUI item for a 'forward' action, like Konqueror's forward button.
A database for tips-of-the-day.
KTipDatabase(const TQString &tipFile=TQString::null)
This constructor reads in the tips from a file with the given name.
void prevTip()
The previous tip will become the current one.
TQString tip() const
Returns the current tip.
void nextTip()
The next tip will become the current one.
KTipDialog(KTipDatabase *db, TQWidget *parent=0, const char *name=0)
Construct a tip dialog.
static void showTip(TQWidget *parent, const TQString &tipFile=TQString::null, bool force=false)
Shows a tip.
static void setShowOnStart(bool show)
Toggles the start behavior.
static void showMultiTip(TQWidget *parent, const TQStringList &tipFiles, bool force=false)
Shows a tip.
static void setIcons(WId win, const TQPixmap &icon, const TQPixmap &miniIcon)
bool readBoolEntry(const TQString &pKey, bool bDefault=false) const
bool hasKey(const TQString &key) const
void writeEntry(const TQString &pKey, const TQString &pValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
TQDateTime readDateTimeEntry(const TQString &pKey, const TQDateTime *pDefault=0L) const
static TQFont generalFont()
static TQColor alternateBackgroundColor()
static TQColor activeTitleColor()
static TQColor textColor()
static TQRect splashScreenDesktopGeometry()
static TDEIconLoader * iconLoader()
static TDEStandardDirs * dirs()
static TDEInstance * instance()
static void colorize(TQImage &image, const TQColor &col, float value)
TQStringList resourceDirs(const char *type) const
kndbgstream & endl(kndbgstream &s)
kdbgstream kdDebug(int area=0)
TQString locate(const char *type, const TQString &filename, const TDEInstance *instance=TDEGlobal::instance())