1 //-----------------------------------------------------------------------------
3 // kblankscrn - Basic screen saver for KDE
5 // Copyright (c) Martin R. Jones 1996
7 // 1998/04/19 Layout management added by Mario Weilguni <mweilguni@kde.org>
8 // 2001/03/04 Converted to use libkscreensaver by Martin R. Jones
9 // 2006/03/12 Ported to KScreenSaverInterface by David Faure
15 #include <QGridLayout>
16 #include <kapplication.h>
19 #include <kcolordialog.h>
20 #include <kcolorbutton.h>
22 #include "blankscrn.h"
23 #include <kaboutdata.h>
24 #include <kdeversion.h>
25 #include "blankscrn.moc"
27 // libkscreensaver interface
28 class KBlankSaverInterface
: public KScreenSaverInterface
31 virtual KAboutData
* aboutData()
33 return new KAboutData( "kblankscrn.kss", 0, ki18n( "KBlankScreen" ),
34 KDE_VERSION_STRING
, ki18n( "Blank Screen Saver" ) );
37 virtual KScreenSaver
* create( WId id
)
39 return new KBlankSaver( id
);
42 virtual QDialog
* setup()
44 return new KBlankSetup();
48 int main( int argc
, char *argv
[] )
50 KBlankSaverInterface kss
;
51 return kScreenSaverMain( argc
, argv
, kss
);
54 //-----------------------------------------------------------------------------
55 // dialog to setup screen saver parameters
57 KBlankSetup::KBlankSetup( QWidget
*parent
, const char *name
)
60 setObjectName( name
);
62 setCaption( i18n( "Setup Blank Screen Saver" ) );
63 setButtons( Ok
| Cancel
);
64 showButtonSeparator( true );
68 QFrame
*main
= new QFrame( this );
69 setMainWidget( main
);
70 QGridLayout
*grid
= new QGridLayout(main
);
71 grid
->setSpacing(spacingHint());
74 QLabel
*label
= new QLabel( i18n("Color:"), main
);
75 grid
->addWidget(label
, 0, 0);
77 KColorButton
*colorPush
= new KColorButton( color
, main
);
78 colorPush
->setMinimumWidth(80);
79 connect( colorPush
, SIGNAL( changed(const QColor
&) ),
80 SLOT( slotColor(const QColor
&) ) );
81 grid
->addWidget(colorPush
, 1, 0);
83 preview
= new QWidget( main
);
84 preview
->setFixedSize( 220, 165 );
86 palette
.setColor( preview
->backgroundRole(), Qt::black
);
87 preview
->setPalette(palette
);
88 preview
->show(); // otherwise saver does not get correct size
89 saver
= new KBlankSaver( preview
->winId() );
90 grid
->addWidget(preview
, 0, 1, 3, 1);
92 grid
->setRowStretch( 2, 10 );
93 grid
->setRowStretch( 3, 20 );
95 setMinimumSize( sizeHint() );
96 connect(this,SIGNAL(okClicked()),this,SLOT(slotOk()));
99 // read settings from config file
100 void KBlankSetup::readSettings()
102 KConfigGroup
config(KGlobal::config(), "Settings");
104 QColor aux
= Qt::black
;
105 color
= config
.readEntry( "Color", aux
);
108 void KBlankSetup::slotColor( const QColor
&col
)
111 saver
->setColor( color
);
114 // Ok pressed - save settings and exit
115 void KBlankSetup::slotOk()
117 KConfigGroup
config(KGlobal::config(), "Settings");
118 config
.writeEntry( "Color", color
);
124 //-----------------------------------------------------------------------------
127 KBlankSaver::KBlankSaver( WId id
) : KScreenSaver( id
)
133 KBlankSaver::~KBlankSaver()
138 void KBlankSaver::setColor( const QColor
&col
)
144 // read configuration settings from config file
145 void KBlankSaver::readSettings()
147 KConfigGroup
config(KGlobal::config(), "Settings");
149 QColor aux
= Qt::black
;
150 color
= config
.readEntry( "Color", aux
);
153 void KBlankSaver::blank()
156 palette
.setColor( backgroundRole(), color
);