00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "look_details.h"
00018 #include <qdir.h>
00019 #include <qcursor.h>
00020 #include "kabentrypainter.h"
00021 #include "global.h"
00022 #include <kdebug.h>
00023 #include <kglobalsettings.h>
00024 #include <kinstance.h>
00025 #include <kstandarddirs.h>
00026 #include <klocale.h>
00027 #include <kconfig.h>
00028 #include <qpainter.h>
00029 #include <qpopupmenu.h>
00030
00031 #define GRID 5
00032
00033 const QString KABDetailedView::BorderedBGDir="kab3part/backgrounds/bordered/";
00034 const QString KABDetailedView::TiledBGDir="kab3part/backgrounds/tiled/";
00035
00036 KABDetailedView::KABDetailedView(QWidget* parent, const char* name)
00037 : KABBasicLook(parent, name),
00038 epainter(0),
00039 bgStyle(None),
00040 defaultBGColor(white),
00041 headlineBGColor(darkBlue),
00042 headlineTextColor(yellow),
00043 Grid(3),
00044 menuBorderedBG(0),
00045 menuTiledBG(0)
00046 {
00047 KToggleAction** actions[]= {
00048 &actionShowAddresses,
00049 &actionShowEmails,
00050 &actionShowTelephones,
00051 &actionShowURLs
00052 };
00053 QString texts[]= {
00054 i18n("Show Postal Addresses"),
00055 i18n("Show Email Addresses"),
00056 i18n("Show Telephone Numbers"),
00057 i18n("Show Web Pages (URLs)")
00058 };
00059 QFont general=KGlobalSettings::generalFont();
00060 QFont fixed=KGlobalSettings::fixedFont();
00061 QString gfont=general.family();
00062 QString ffont=fixed.family();
00063 int gpointsize=general.pixelSize();
00064 if ( gpointsize == -1 )
00065 gpointsize = general.pointSize();
00066
00067 int fpointsize=fixed.pixelSize();
00068 if ( fpointsize == -1 )
00069 fpointsize = fixed.pointSize();
00070
00071 epainter=new KABEntryPainter
00072 (Qt::black, headlineTextColor,
00073 useHeadlineBGColor, headlineBGColor,
00074 QFont(gfont, gpointsize+4, QFont::Bold, true),
00075 QFont(gfont, gpointsize+2, QFont::Bold, true),
00076 QFont(gfont, gpointsize, QFont::Normal, false),
00077 QFont(ffont, fpointsize, QFont::Normal, false),
00078 QFont(gfont, gpointsize, QFont::Normal, false));
00079 const int Size=sizeof(actions)/sizeof(actions[0]);
00080
00081 for(int count=0; count<Size; ++count)
00082 {
00083 *actions[count]=new KToggleAction(texts[count]);
00084 (*actions[count])->setChecked(true);
00085 }
00086
00087 setMouseTracking(true);
00088
00089
00090
00091
00092
00093
00094
00095
00096 }
00097
00098 KABDetailedView::~KABDetailedView()
00099 {
00100 if(epainter!=0) delete epainter;
00101 }
00102
00103 bool KABDetailedView::getBackground(QString path, QPixmap& image)
00104 {
00105 QMap<QString, QPixmap>::iterator pos;
00106 pos=backgrounds.find(path);
00107 if(pos==backgrounds.end())
00108 {
00109 if(image.load(path))
00110 {
00111 backgrounds[path]=image;
00112 return true;
00113 } else {
00114 return false;
00115 }
00116 } else {
00117
00118 image=pos.data();
00119 return true;
00120 }
00121 }
00122
00123 void KABDetailedView::paintEvent(QPaintEvent*)
00124 {
00125 const int BorderSpace=Grid;
00126 QPixmap pm(width(), height());
00127 QPainter p;
00128 QRect entryArea=QRect(BorderSpace, Grid, width()-Grid-BorderSpace,
00129 height()-2*Grid);
00130 p.begin(&pm);
00131
00132 p.setPen(darkBlue);
00133 p.setBrush(defaultBGColor);
00134 p.drawRect(0, 0, width(), height());
00135 switch(bgStyle)
00136 {
00137 case Tiled:
00138 p.drawTiledPixmap(1, 1, width()-2, height()-2, background);
00139 break;
00140 case Bordered:
00141 p.drawTiledPixmap(1, 1,
00142 QMIN(width()-2,
00143 background.width()),
00144 height()-2, background);
00145 break;
00146 case None:
00147 default:
00148 if(useDefaultBGImage)
00149 {
00150 p.drawTiledPixmap(1, 1, width()-2, height()-2, defaultBGImage);
00151 }
00152 break;
00153 };
00154 p.setViewport(entryArea);
00155 epainter->setShowAddresses(actionShowAddresses->isChecked());
00156 epainter->setShowEmails(actionShowEmails->isChecked());
00157 epainter->setShowTelephones(actionShowTelephones->isChecked());
00158 epainter->setShowURLs(actionShowURLs->isChecked());
00159 epainter->printEntry(current,
00160 QRect(0, 0, entryArea.width(), entryArea.height()),
00161 &p);
00162 p.end();
00163 bitBlt(this, 0, 0, &pm);
00164 }
00165
00166 void KABDetailedView::mouseMoveEvent(QMouseEvent *e)
00167 {
00168 QPoint bias(Grid, Grid);
00169 int rc;
00170 bool hit=false;
00171
00172 if((rc=epainter->hitsEmail(e->pos()-bias))!=-1)
00173 {
00174
00175
00176
00177 hit=true;
00178 }
00179 else
00180 if((rc=epainter->hitsURLs(e->pos()-bias))!=-1)
00181 {
00182
00183
00184
00185 hit=true;
00186 }
00187 else
00188 if((rc=epainter->hitsTelephones(e->pos()-bias))!=-1)
00189 {
00190
00191
00192
00193 hit=true;
00194 }
00195 else
00196 if((rc=epainter->hitsTalkAddresses(e->pos()-bias))!=-1)
00197 {
00198
00199
00200
00201 hit=true;
00202 }
00203 if(hit)
00204 {
00205 if(cursor().shape()!=PointingHandCursor)
00206 {
00207 setCursor(PointingHandCursor);
00208 }
00209 } else {
00210 if(cursor().shape()!=ArrowCursor)
00211 {
00212 setCursor(ArrowCursor);
00213 }
00214 }
00215 }
00216
00217 void KABDetailedView::mousePressEvent(QMouseEvent *e)
00218 {
00219 QPopupMenu menu(this);
00220 QPopupMenu *menuBG=new QPopupMenu(&menu);
00221 menuBorderedBG=new QPopupMenu(&menu);
00222 menuTiledBG=new QPopupMenu(&menu);
00223 menu.insertItem(i18n("Select Background"), menuBG);
00224 menuBG->insertItem(i18n("Bordered Backgrounds"), menuBorderedBG);
00225 menuBG->insertItem(i18n("Tiled Backgrounds"), menuTiledBG);
00226 menu.insertSeparator();
00227 QPoint point=e->pos()-QPoint(Grid, Grid);
00228 int rc;
00229 QStringList dirsBorderedBG, dirsTiledBG;
00230 QDir dir;
00231
00232 switch(e->button())
00233 {
00234 case QMouseEvent::RightButton:
00235 if(m_ro)
00236 {
00237 menu.setItemEnabled(menu.idAt(0), false);
00238 } else {
00239
00240
00241 dirsBorderedBG=KGlobal::instance()->dirs()->findDirs
00242 ("data", BorderedBGDir);
00243 if(dirsBorderedBG.count()>0)
00244 {
00245 dir.setPath(dirsBorderedBG[0]);
00246 borders=dir.entryList(QDir::Files);
00247 for(unsigned count=0; count<borders.count(); ++count)
00248 {
00249 menuBorderedBG->insertItem(borders[count], count);
00250 }
00251 connect(menuBorderedBG, SIGNAL(activated(int)),
00252 this, SLOT(slotBorderedBGSelected(int)));
00253 } else {
00254 menuBG->setItemEnabled(menuBG->idAt(0), false);
00255 }
00256 dirsTiledBG=KGlobal::instance()->dirs()->findDirs
00257 ("data", TiledBGDir);
00258 if(dirsTiledBG.count()>0)
00259 {
00260 dir.setPath(dirsTiledBG[0]);
00261 tiles=dir.entryList(QDir::Files);
00262 for(unsigned count=0; count<tiles.count(); ++count)
00263 {
00264 menuTiledBG->insertItem(tiles[count], count);
00265 }
00266 connect(menuTiledBG, SIGNAL(activated(int)),
00267 this, SLOT(slotTiledBGSelected(int)));
00268 } else {
00269 menuBG->setItemEnabled(menuBG->idAt(1), false);
00270 }
00271 }
00272
00273 actionShowAddresses->plug(&menu);
00274 actionShowEmails->plug(&menu);
00275 actionShowTelephones->plug(&menu);
00276 actionShowURLs->plug(&menu);
00277
00278 menu.exec(e->globalPos());
00279 break;
00280 case QMouseEvent::LeftButton:
00281
00282
00283 if((rc=epainter->hitsEmail(point))!=-1)
00284 {
00285 emit(sendEmail(current.emails()[rc]));
00286 break;
00287 }
00288 if((rc=epainter->hitsURLs(point))!=-1)
00289 {
00290 emit(browse(current.url().prettyURL()));
00291 break;
00292 }
00293 if((rc=epainter->hitsTelephones(point))!=-1)
00294 {
00295
00296
00297 kdDebug() << "KABDetailedView::mousePressEvent: ni (calling)."
00298 << endl;
00299 break;
00300 }
00301 if((rc=epainter->hitsTalkAddresses(point))!=-1)
00302 {
00303
00304 kdDebug() << "KABDetailedView::mousePressEvent: ni (invoking ktalk)."
00305 << endl;
00306 break;
00307 }
00308 kdDebug() << "KABDetailedView::mousePressEvent: not over active item."
00309 << endl;
00310 break;
00311 default:
00312 break;
00313 };
00314 menuBorderedBG=0;
00315 menuTiledBG=0;
00316 }
00317
00318 void KABDetailedView::setEntry(const KABC::Addressee& e)
00319 {
00320
00321 BackgroundStyle style=None;
00322 QString dir, file, styleSetting;
00323 KABBasicLook::setEntry(e);
00324
00325
00326 styleSetting=current.custom("kab", "BackgroundStyle");
00327 style=(BackgroundStyle)styleSetting.toInt();
00328 file=current.custom("kab", "BackgroundImage");
00329 if(!file.isEmpty())
00330 {
00331 switch(style)
00332 {
00333 case Tiled:
00334 dir=TiledBGDir;
00335 break;
00336 case Bordered:
00337 dir=BorderedBGDir;
00338 break;
00339 case None:
00340 default:
00341 break;
00342 }
00343
00344 QStringList dirs;
00345 dirs=KGlobal::instance()->dirs()->findDirs("data", dir);
00346 bgStyle=None;
00347 if(!dirs.isEmpty())
00348 {
00349 unsigned count;
00350 for(count=0; count<dirs.count(); ++count)
00351 {
00352 QDir folder;
00353 folder.setPath(dirs[count]);
00354 file=folder.absPath()+"/"+file;
00355 if(getBackground(file, background))
00356 {
00357 bgStyle=style;
00358 break;
00359 }
00360 }
00361 if(count==dirs.count())
00362 {
00363 kdDebug() << "KABDetailedView::setEntry: " << file
00364 << " not locatable." << endl;
00365 }
00366 }
00367 } else {
00368 bgStyle=None;
00369 background.resize(0,0);
00370 }
00371 repaint(false);
00372 }
00373
00374 void KABDetailedView::slotBorderedBGSelected(int index)
00375 {
00376 if(index>=0 && (unsigned)index<borders.count() && !readonly())
00377 {
00378
00379 QString path=borders[index];
00380 bgStyle=Bordered;
00381 current.insertCustom("kab", "BackgroundStyle", QString().setNum(bgStyle));
00382 current.insertCustom("kab", "BackgroundImage", path);
00383 setEntry(current);
00384 emit(entryChanged());
00385 }
00386 }
00387
00388 void KABDetailedView::slotTiledBGSelected(int index)
00389 {
00390 if(index>=0 && (unsigned)index<tiles.count() && !readonly())
00391 {
00392 QString path=tiles[index];
00393 bgStyle=Tiled;
00394 current.insertCustom("kab", "BackgroundStyle", QString().setNum(bgStyle));
00395 current.insertCustom("kab", "BackgroundImage", path);
00396 setEntry(current);
00397 emit(entryChanged());
00398 }
00399 }
00400
00401
00402 void KABDetailedView::setReadonly(bool state)
00403 {
00404 KABBasicLook::setReadonly(state);
00405 repaint(false);
00406 }
00407
00408 void KABDetailedView::configure(KConfig *config)
00409 {
00410 QFont general=KGlobalSettings::generalFont();
00411 QFont fixed=KGlobalSettings::fixedFont();
00412 QString gfont=general.family();
00413 QString ffont=fixed.family();
00414
00415 int gpointsize=general.pixelSize();
00416 if ( gpointsize == -1 )
00417 gpointsize = general.pointSize();
00418
00419 int fpointsize=fixed.pixelSize();
00420 if ( fpointsize == -1 )
00421 fpointsize = fixed.pointSize();
00422
00423
00424 bool useBGImage=true;
00425 config->setGroup(ConfigView);
00426
00427 QString bgImage;
00428 useDefaultBGImage=config->readBoolEntry
00429 (ConfigView_UseDefaultBackground, useBGImage);
00430 defaultBGColor=config->readColorEntry
00431 (ConfigView_DefaultBackgroundColor, &white);
00432 bgImage=config->readEntry
00433 (ConfigView_DefaultBackgroundImage,
00434 "konqueror/tiles/kenwimer.png");
00435 if(useDefaultBGImage)
00436 {
00437 unsigned count=0;
00438 QStringList dirs=KGlobal::instance()->dirs()->findDirs("data", "/");
00439 if(!dirs.isEmpty())
00440 {
00441 for(count=0; count<dirs.count(); ++count)
00442 {
00443
00444 if(getBackground(dirs[count] + "/" + bgImage, defaultBGImage))
00445 {
00446 break;
00447 }
00448 }
00449 }
00450 if(count==dirs.count())
00451 {
00452 useDefaultBGImage=getBackground(bgImage, defaultBGImage);
00453 if(!useDefaultBGImage)
00454 {
00455 kdDebug() << "KABDetailedView::configure: "
00456 << "default BG image selected, but could not be loaded."
00457 << endl;
00458 }
00459 }
00460 }
00461
00462
00463
00464
00465
00466
00467
00468 defaultBGColor=config->readColorEntry
00469 (ConfigView_DefaultBackgroundColor, &white);
00470
00471 headlineBGColor=config->readColorEntry
00472 (ConfigView_HeadlineBGColor, &darkBlue);
00473 headlineTextColor=config->readColorEntry
00474 (ConfigView_HeadlineTextColor, &yellow);
00475 useHeadlineBGColor=config->readBoolEntry(ConfigView_UseHeadlineBGColor, true);
00476
00477 if(epainter!=0)
00478 {
00479 delete epainter;
00480 epainter=0;
00481 }
00482 epainter=new KABEntryPainter
00483 (Qt::black, headlineTextColor,
00484 useHeadlineBGColor, headlineBGColor,
00485 QFont(gfont, gpointsize+4, QFont::Bold, true),
00486 QFont(gfont, gpointsize+2, QFont::Bold, true),
00487 QFont(gfont, gpointsize, QFont::Normal, false),
00488 QFont(ffont, fpointsize, QFont::Normal, false),
00489 QFont(gfont, gpointsize, QFont::Normal, false));
00490 }
00491
00492
00493 #include "look_details.moc"