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