not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / kscreensaver / kblank_screensaver / blankscrn.cpp
blob682bba387ba91865a0268a312d4a3dffed89f53b
1 //-----------------------------------------------------------------------------
2 //
3 // kblankscrn - Basic screen saver for KDE
4 //
5 // Copyright (c) Martin R. Jones 1996
6 //
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
11 #include <stdlib.h>
12 #include <QLabel>
13 #include <QLayout>
14 #include <QFrame>
15 #include <QGridLayout>
16 #include <kapplication.h>
17 #include <klocale.h>
18 #include <kconfig.h>
19 #include <kcolordialog.h>
20 #include <kcolorbutton.h>
21 #include <kglobal.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
30 public:
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 )
58 : KDialog( parent )
60 setObjectName( name );
61 setModal( true );
62 setCaption( i18n( "Setup Blank Screen Saver" ) );
63 setButtons( Ok | Cancel );
64 showButtonSeparator( true );
66 readSettings();
68 QFrame *main = new QFrame( this );
69 setMainWidget( main );
70 QGridLayout *grid = new QGridLayout(main);
71 grid->setSpacing(spacingHint());
72 grid->setMargin(0);
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 );
85 QPalette palette;
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 )
110 color = 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 );
119 config.sync();
121 accept();
124 //-----------------------------------------------------------------------------
127 KBlankSaver::KBlankSaver( WId id ) : KScreenSaver( id )
129 readSettings();
130 blank();
133 KBlankSaver::~KBlankSaver()
137 // set the color
138 void KBlankSaver::setColor( const QColor &col )
140 color = col;
141 blank();
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()
155 QPalette palette;
156 palette.setColor( backgroundRole(), color );
157 setPalette(palette);