summaryrefslogtreecommitdiffstats
path: root/kgamma/kcmkgamma
diff options
context:
space:
mode:
Diffstat (limited to 'kgamma/kcmkgamma')
-rw-r--r--kgamma/kcmkgamma/Makefile.am18
-rw-r--r--kgamma/kcmkgamma/displaynumber.cpp61
-rw-r--r--kgamma/kcmkgamma/displaynumber.h41
-rw-r--r--kgamma/kcmkgamma/gammactrl.cpp138
-rw-r--r--kgamma/kcmkgamma/gammactrl.h76
-rw-r--r--kgamma/kcmkgamma/kgamma.cpp625
-rw-r--r--kgamma/kcmkgamma/kgamma.desktop129
-rw-r--r--kgamma/kcmkgamma/kgamma.h78
-rw-r--r--kgamma/kcmkgamma/pics/Makefile.am7
-rw-r--r--kgamma/kcmkgamma/pics/background.pngbin0 -> 167 bytes
-rw-r--r--kgamma/kcmkgamma/pics/cmyscale.pngbin0 -> 1033 bytes
-rw-r--r--kgamma/kcmkgamma/pics/darkgrey.pngbin0 -> 502 bytes
-rw-r--r--kgamma/kcmkgamma/pics/greyscale.pngbin0 -> 428 bytes
-rw-r--r--kgamma/kcmkgamma/pics/hi16-app-kgamma.pngbin0 -> 427 bytes
-rw-r--r--kgamma/kcmkgamma/pics/hi32-app-kgamma.pngbin0 -> 1015 bytes
-rw-r--r--kgamma/kcmkgamma/pics/hi48-app-kgamma.pngbin0 -> 1314 bytes
-rw-r--r--kgamma/kcmkgamma/pics/lightgrey.pngbin0 -> 473 bytes
-rw-r--r--kgamma/kcmkgamma/pics/midgrey.pngbin0 -> 509 bytes
-rw-r--r--kgamma/kcmkgamma/pics/rgbscale.pngbin0 -> 752 bytes
-rw-r--r--kgamma/kcmkgamma/xf86configpath.cpp56
-rw-r--r--kgamma/kcmkgamma/xf86configpath.h42
-rw-r--r--kgamma/kcmkgamma/xvidextwrap.cpp170
-rw-r--r--kgamma/kcmkgamma/xvidextwrap.h59
23 files changed, 1500 insertions, 0 deletions
diff --git a/kgamma/kcmkgamma/Makefile.am b/kgamma/kcmkgamma/Makefile.am
new file mode 100644
index 00000000..6420ee92
--- /dev/null
+++ b/kgamma/kcmkgamma/Makefile.am
@@ -0,0 +1,18 @@
+
+INCLUDES = $(all_includes)
+
+kde_module_LTLIBRARIES = kcm_kgamma.la
+kcm_kgamma_la_METASOURCES=AUTO
+kcm_kgamma_la_SOURCES = xf86configpath.cpp xvidextwrap.cpp displaynumber.cpp \
+ gammactrl.cpp kgamma.cpp
+kcm_kgamma_la_LIBADD = $(LIBVM) $(LIB_KDEUI) $(LIB_KDECORE) $(LIB_QT)
+kcm_kgamma_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN)
+
+SUBDIRS = pics
+
+xdg_apps_DATA = kgamma.desktop
+
+messages:
+ $(XGETTEXT) *.cpp -o $(podir)/kgamma.pot
+
+KDE_OPTIONS = nofinal
diff --git a/kgamma/kcmkgamma/displaynumber.cpp b/kgamma/kcmkgamma/displaynumber.cpp
new file mode 100644
index 00000000..cb04f513
--- /dev/null
+++ b/kgamma/kcmkgamma/displaynumber.cpp
@@ -0,0 +1,61 @@
+/***************************************************************************
+ displaynumber.cpp - description
+ -------------------
+ begin : Sun Feb 23 2003
+ copyright : (C) 2003 by Michael v.Ostheim
+ email : ostheimm@users.berlios.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include <qstring.h>
+#include <qfontmetrics.h>
+
+#include "displaynumber.h"
+
+DisplayNumber::DisplayNumber(QWidget *parent, int digits, \
+ int prec, const char *name) : QLabel(parent,name) {
+
+ setPrecision(prec);
+ setWidth(digits);
+
+ setFrameStyle(QFrame::Panel | QFrame::Sunken);
+ setBackgroundMode(Qt::PaletteBase);
+ setAlignment(Qt::AlignCenter);
+ setFocusPolicy(NoFocus);
+}
+
+DisplayNumber::~DisplayNumber(){
+}
+
+void DisplayNumber::setFont( const QFont & f ) {
+ QLabel::setFont(f);
+ setWidth(dg);
+}
+
+void DisplayNumber::setWidth(int digits) {
+ QFontMetrics fm(font());
+ QString s("0123456789.+-");
+ int width = 0, charWidth=0;
+
+ for (int i = 0; i < 11; i++, width = fm.width(s[i]))
+ charWidth = (width > charWidth) ? width : charWidth;
+
+ dg = digits;
+ setMinimumWidth( dg * charWidth + charWidth/2 );
+}
+
+void DisplayNumber::setNum(double num) {
+ QString text;
+ setText(text.setNum(num, 'f', precision));
+}
+
+
+#include "displaynumber.moc"
diff --git a/kgamma/kcmkgamma/displaynumber.h b/kgamma/kcmkgamma/displaynumber.h
new file mode 100644
index 00000000..e86d6d3a
--- /dev/null
+++ b/kgamma/kcmkgamma/displaynumber.h
@@ -0,0 +1,41 @@
+/***************************************************************************
+ displaynumber.h - description
+ -------------------
+ begin : Sun Feb 23 2003
+ copyright : (C) 2003 by Michael v.Ostheim
+ email : ostheimm@users.berlios.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef DISPLAYNUMBER_H
+#define DISPLAYNUMBER_H
+
+#include <qlabel.h>
+
+/**
+ *@author Michael v.Ostheim
+ */
+
+class DisplayNumber : public QLabel {
+ Q_OBJECT
+public:
+ DisplayNumber(QWidget *parent=0, int digits=0, int prec=0, const char *name=0);
+ ~DisplayNumber();
+ void setFont( const QFont & f );
+ void setNum(double num);
+ void setWidth(int digits);
+ void setPrecision(int prec) { precision = prec; };
+
+private:
+ int dg, precision;
+};
+
+#endif
diff --git a/kgamma/kcmkgamma/gammactrl.cpp b/kgamma/kcmkgamma/gammactrl.cpp
new file mode 100644
index 00000000..2052fd34
--- /dev/null
+++ b/kgamma/kcmkgamma/gammactrl.cpp
@@ -0,0 +1,138 @@
+/***************************************************************************
+ gammactrl.cpp - description
+ -------------------
+ begin : Sun Oct 7 2001
+ copyright : (C) 2001 by Michael v.Ostheim
+ email : MvOstheim@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include <qlabel.h>
+#include <qlineedit.h>
+#include <qstring.h>
+
+#include <kdialog.h>
+
+#include "gammactrl.h"
+#include "xvidextwrap.h"
+#include "displaynumber.h"
+#include "gammactrl.moc"
+
+GammaCtrl::GammaCtrl(QWidget *parent, XVidExtWrap *xvid, int channel, \
+ const QString& mingamma, const QString& maxgamma, const QString& setgamma, \
+ const char *name) : QHBox(parent, name)
+{
+ int maxslider = (int)( ( maxgamma.toDouble() - mingamma.toDouble() \
+ + 0.0005 ) * 20 );
+ int setslider = (int)( ( setgamma.toDouble() - mingamma.toDouble() \
+ + 0.0005 ) * 20 );
+ setslider = (setslider > maxslider) ? maxslider : setslider;
+ setslider = (setslider < 0) ? 0 : setslider;
+
+ suspended = false;
+ changed=false;
+ ming = mingamma.toFloat();
+ mgamma = mingamma;
+ oldpos = setslider;
+ gchannel = channel;
+ xv = xvid;
+
+ setSpacing(KDialog::spacingHint());
+
+ slider = new QSlider(Horizontal, this);
+ slider->setFixedHeight(24);
+ slider->setTickmarks(QSlider::Below);
+ slider->setRange(0, maxslider);
+ slider->setTickInterval(2);
+ slider->setValue(setslider);
+ connect(slider, SIGNAL(valueChanged(int)), SLOT(setGamma(int)));
+ connect(slider, SIGNAL(sliderPressed()), SLOT(pressed()));
+
+ textfield = new DisplayNumber(this, 4, 2);
+ textfield->setText(setgamma);
+
+}
+
+GammaCtrl::~GammaCtrl()
+{
+}
+
+/** set gamma, slider and textfield */
+void GammaCtrl::setGamma(const QString& gamma){
+ int sliderpos;
+
+ sliderpos = (int)( ( gamma.toDouble() - mgamma.toDouble() + 0.0005 ) * 20 );
+ changed=true;
+ slider->setValue(sliderpos);
+
+ setGamma(sliderpos);
+ if (suspended) {
+ suspended=false;
+ textfield->setDisabled(false);
+ }
+}
+
+/** set slider and textfield */
+void GammaCtrl::setControl(const QString& gamma){
+ int sliderpos;
+
+ sliderpos = (int)( ( gamma.toDouble() - mgamma.toDouble() + 0.0005 ) * 20 );
+ setCtrl(sliderpos);
+}
+
+/** Return the current gamma value with precision prec */
+QString GammaCtrl::gamma(int prec){
+ QString gammatext;
+ gammatext.setNum(xv->getGamma(gchannel) + 0.0005, 'f', prec);
+
+ return(gammatext);
+}
+
+/** Slot: set gamma and textfield */
+void GammaCtrl::setGamma(int sliderpos){
+ if (sliderpos != oldpos || changed) {
+ xv->setGamma(gchannel, ming+(float)(slider->value())*0.05);
+ textfield->setNum(xv->getGamma(gchannel));
+ oldpos = sliderpos;
+ changed=false;
+ emit gammaChanged(sliderpos);
+ }
+}
+
+/** Slot: set slider and textfield */
+void GammaCtrl::setCtrl(int sliderpos){
+ if (suspended) {
+ suspended=false;
+ textfield->setDisabled(false);
+ }
+ oldpos = sliderpos;
+ slider->setValue(sliderpos);
+ textfield->setNum(xv->getGamma(gchannel));
+}
+
+/** Slot: disable textfield */
+void GammaCtrl::suspend(){
+ if (!suspended) {
+ suspended = true;
+ textfield->setDisabled(true);
+ }
+}
+
+/** Slot: Change status of GammaCtrl when pressed */
+void GammaCtrl::pressed(){
+ if (suspended) {
+ suspended=false;
+ textfield->setDisabled(false);
+ changed=true;
+ setGamma(slider->value());
+ }
+}
+
diff --git a/kgamma/kcmkgamma/gammactrl.h b/kgamma/kcmkgamma/gammactrl.h
new file mode 100644
index 00000000..0d6ea890
--- /dev/null
+++ b/kgamma/kcmkgamma/gammactrl.h
@@ -0,0 +1,76 @@
+/***************************************************************************
+ gammactrl.h - description
+ -------------------
+ begin : Sun Oct 7 2001
+ copyright : (C) 2001 by Michael v.Ostheim
+ email : MvOstheim@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+/**A horizontal slider and a text field for the gamma value.
+ *@author Michael v.Ostheim
+ */
+
+#ifndef GAMMACTRL_H
+#define GAMMACTRL_H
+
+#include <qhbox.h>
+#include <qslider.h>
+
+class QString;
+class DisplayNumber;
+class XVidExtWrap;
+
+class GammaCtrl : public QHBox {
+
+ Q_OBJECT
+ public:
+ /** construktor */
+ GammaCtrl(QWidget *parent=0, XVidExtWrap *xvid=0, int channel=0, \
+ const QString& mingamma="0.40", const QString& maxgamma="3.50", \
+ const QString& setgamma="1.00", const char *name=0 );
+ /** destruktor */
+ ~GammaCtrl();
+ /** Return the current gamma value with precision prec */
+ QString gamma(int);
+ /** Set gamma, slider and textfield */
+ void setGamma(const QString&);
+ /** Set slider and textfield */
+ void setControl(const QString&);
+ /** Disable the slider */
+ void disableSlider() { slider->setDisabled(true);};
+
+ private:
+ QString mgamma;
+ QSlider *slider;
+ DisplayNumber *textfield;
+ bool suspended, changed;
+ int gchannel, oldpos;
+ double ming;
+ XVidExtWrap *xv;
+
+ public slots:
+ /** Disable textfield */
+ void suspend();
+
+ protected slots:
+ /** Set slider and textfield */
+ void setCtrl(int);
+ /** Set gamma and textfield */
+ void setGamma(int);
+ /** Change status of GammaCtrl when pressed */
+ void pressed();
+
+ signals:
+ /** Gamma change signal */
+ void gammaChanged(int);
+};
+
+#endif
diff --git a/kgamma/kcmkgamma/kgamma.cpp b/kgamma/kcmkgamma/kgamma.cpp
new file mode 100644
index 00000000..427d01c4
--- /dev/null
+++ b/kgamma/kcmkgamma/kgamma.cpp
@@ -0,0 +1,625 @@
+/***************************************************************************
+ kgamma.cpp - description
+ -------------------
+ begin : Sun Dec 16 13:52:24 CET 2001
+ copyright : (C) 2001 by Michael v.Ostheim
+ email : MvOstheim@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include <unistd.h>
+
+#include <qlabel.h>
+#include <qpixmap.h>
+#include <qstring.h>
+#include <qlayout.h>
+#include <qstringlist.h>
+#include <qdir.h>
+#include <qcheckbox.h>
+#include <qcombobox.h>
+#include <qwidgetstack.h>
+
+#include <kstandarddirs.h>
+#include <kconfig.h>
+#include <klocale.h>
+#include <kglobal.h>
+#include <kprocess.h>
+#include <kdialog.h>
+#include <kgenericfactory.h>
+
+#include "config.h"
+#include "xf86configpath.h"
+#include "gammactrl.h"
+#include "xvidextwrap.h"
+#include "kgamma.h"
+#include "kgamma.moc"
+
+typedef KGenericFactory<KGamma, QWidget> KGammaFactory;
+K_EXPORT_COMPONENT_FACTORY ( kcm_kgamma, KGammaFactory( "kgamma" ) )
+
+extern "C"
+{
+ bool test_kgamma()
+ {
+ bool retval;
+ (void) new XVidExtWrap(&retval, NULL);
+ return retval;
+ }
+}
+
+KGamma::KGamma(QWidget *parent, const char *name, const QStringList&)
+ :KCModule(parent,name)
+{
+ bool ok;
+ GammaCorrection = true;
+ xv = new XVidExtWrap(&ok, NULL);
+ if (ok) { /* KDE 4: Uneccessary test, when all KCM wrappers do conditional loading */
+ xv->getGamma(XVidExtWrap::Red, &ok);
+ if (ok) {
+ ScreenCount = xv->_ScreenCount();
+ currentScreen = xv->getScreen();
+ xv->setGammaLimits(0.4, 3.5);
+
+ for (int i = 0; i < ScreenCount; i++ ) {
+ assign << 0;
+ rgamma << "";
+ ggamma << "";
+ bgamma << "";
+
+ // Store the current gamma values
+ xv->setScreen(i);
+ rbak << xv->getGamma(XVidExtWrap::Red);
+ gbak << xv->getGamma(XVidExtWrap::Green);
+ bbak << xv->getGamma(XVidExtWrap::Blue);
+ }
+ xv->setScreen(currentScreen);
+
+ rootProcess = new KProcess;
+ setupUI();
+ saved = false;
+
+ if (!loadSettings()) { //try to load gamma values from config file
+ // if failed, take current gamma values
+ for (int i = 0; i < ScreenCount; i++ ) {
+ rgamma[i].setNum(rbak[i], 'f', 2);
+ ggamma[i].setNum(gbak[i], 'f', 2);
+ bgamma[i].setNum(bbak[i], 'f', 2);
+ }
+ }
+ load();
+ }
+ else { //something is wrong, show only error message
+ GammaCorrection = false;
+ setupUI();
+ }
+ }
+}
+
+KGamma::~KGamma() {
+ // Restore the old gamma settings, if the user has not saved
+ // and there is no valid kgammarc.
+ // Existing user settings overwrite system settings
+ if (GammaCorrection) {
+ if ( loadUserSettings() ) load();
+ else if ( !saved )
+ for (int i = 0; i < ScreenCount; i++ ) {
+ xv->setScreen(i);
+ xv->setGamma( XVidExtWrap::Red, rbak[i] );
+ xv->setGamma( XVidExtWrap::Green, gbak[i] );
+ xv->setGamma( XVidExtWrap::Blue, bbak[i] );
+ }
+ delete rootProcess;
+ }
+ delete xv;
+}
+
+/** User interface */
+void KGamma::setupUI() {
+ QBoxLayout *topLayout = new QVBoxLayout(this, 0, KDialog::spacingHint());
+
+ if (GammaCorrection) {
+ QHBoxLayout *hbox = new QHBoxLayout( topLayout );
+ QLabel *label = new QLabel( i18n( "&Select test picture:" ) , this);
+ QComboBox *combo = new QComboBox( this );
+ label->setBuddy( combo );
+
+ QStringList list;
+ list << i18n( "Gray Scale" )
+ << i18n( "RGB Scale" )
+ << i18n( "CMY Scale" )
+ << i18n( "Dark Gray" )
+ << i18n( "Mid Gray" )
+ << i18n( "Light Gray" );
+ combo->insertStringList( list );
+
+ hbox->addWidget( label );
+ hbox->addWidget( combo );
+ hbox->addStretch();
+
+ QWidgetStack *stack = new QWidgetStack( this );
+ stack->setFrameStyle( QFrame::Box | QFrame::Raised );
+
+ connect( combo, SIGNAL( activated( int ) ),
+ stack, SLOT( raiseWidget( int ) ) );
+
+ QPixmap background;
+ background.load(locate("data", "kgamma/pics/background.png"));
+
+ QLabel *pic1 = new QLabel(stack);
+ pic1->setMinimumSize(530, 171);
+ pic1->setBackgroundPixmap(background);
+ pic1->setPixmap(QPixmap(locate("data", "kgamma/pics/greyscale.png")));
+ pic1->setAlignment(AlignCenter);
+ stack->addWidget( pic1, 0 );
+
+ QLabel *pic2 = new QLabel(stack);
+ pic2->setBackgroundPixmap(background);
+ pic2->setPixmap(QPixmap(locate("data", "kgamma/pics/rgbscale.png")));
+ pic2->setAlignment(AlignCenter);
+ stack->addWidget( pic2, 1 );
+
+ QLabel *pic3 = new QLabel(stack);
+ pic3->setBackgroundPixmap(background);
+ pic3->setPixmap(QPixmap(locate("data", "kgamma/pics/cmyscale.png")));
+ pic3->setAlignment(AlignCenter);
+ stack->addWidget( pic3, 2 );
+
+ QLabel *pic4 = new QLabel(stack);
+ pic4->setBackgroundPixmap(background);
+ pic4->setPixmap(QPixmap(locate("data", "kgamma/pics/darkgrey.png")));
+ pic4->setAlignment(AlignCenter);
+ stack->addWidget( pic4, 3 );
+
+ QLabel *pic5 = new QLabel(stack);
+ pic5->setBackgroundPixmap(background);
+ pic5->setPixmap(QPixmap(locate("data", "kgamma/pics/midgrey.png")));
+ pic5->setAlignment(AlignCenter);
+ stack->addWidget( pic5, 4 );
+
+ QLabel *pic6 = new QLabel(stack);
+ pic6->setBackgroundPixmap(background);
+ pic6->setPixmap(QPixmap(locate("data", "kgamma/pics/lightgrey.png")));
+ pic6->setAlignment(AlignCenter);
+ stack->addWidget( pic6, 5 );
+
+ topLayout->addWidget(stack, 10);
+
+ //Sliders for gamma correction
+ QFrame *frame1 = new QFrame(this);
+ frame1->setFrameStyle( QFrame::GroupBoxPanel | QFrame::Plain );
+
+ QFrame *frame2 = new QFrame(this);
+ frame2->setFrameStyle( QFrame::GroupBoxPanel | QFrame::Plain );
+
+ QLabel *gammalabel = new QLabel(this);
+ gammalabel->setText(i18n("Gamma:"));
+
+ QLabel *redlabel = new QLabel(this);
+ redlabel->setText(i18n("Red:"));
+
+ QLabel *greenlabel = new QLabel(this);
+ greenlabel->setText(i18n("Green:"));
+
+ QLabel *bluelabel = new QLabel(this);
+ bluelabel->setText(i18n("Blue:"));
+
+ gctrl = new GammaCtrl(this, xv);
+ connect(gctrl, SIGNAL(gammaChanged(int)), SLOT(Changed()));
+ connect(gctrl, SIGNAL(gammaChanged(int)), SLOT(SyncScreens()));
+ gammalabel->setBuddy( gctrl );
+
+ rgctrl = new GammaCtrl(this, xv, XVidExtWrap::Red);
+ connect(rgctrl, SIGNAL(gammaChanged(int)), SLOT(Changed()));
+ connect(rgctrl, SIGNAL(gammaChanged(int)), SLOT(SyncScreens()));
+ connect(gctrl, SIGNAL(gammaChanged(int)), rgctrl, SLOT(setCtrl(int)));
+ connect(rgctrl, SIGNAL(gammaChanged(int)), gctrl, SLOT(suspend()));
+ redlabel->setBuddy( rgctrl );
+
+ ggctrl = new GammaCtrl(this, xv, XVidExtWrap::Green);
+ connect(ggctrl, SIGNAL(gammaChanged(int)), SLOT(Changed()));
+ connect(ggctrl, SIGNAL(gammaChanged(int)), SLOT(SyncScreens()));
+ connect(gctrl, SIGNAL(gammaChanged(int)), ggctrl, SLOT(setCtrl(int)));
+ connect(ggctrl, SIGNAL(gammaChanged(int)), gctrl, SLOT(suspend()));
+ greenlabel->setBuddy( ggctrl );
+
+ bgctrl = new GammaCtrl(this, xv, XVidExtWrap::Blue);
+ connect(bgctrl, SIGNAL(gammaChanged(int)), SLOT(Changed()));
+ connect(bgctrl, SIGNAL(gammaChanged(int)), SLOT(SyncScreens()));
+ connect(gctrl, SIGNAL(gammaChanged(int)), bgctrl, SLOT(setCtrl(int)));
+ connect(bgctrl, SIGNAL(gammaChanged(int)), gctrl, SLOT(suspend()));
+ bluelabel->setBuddy( bgctrl );
+
+ QGridLayout *grid = new QGridLayout(4, 9);
+ grid->setSpacing(8);
+ grid->addMultiCellWidget(frame1, 0, 2, 0, 3);
+ grid->addMultiCellWidget(frame2, 4, 8, 0, 3);
+ grid->addWidget(gammalabel, 1, 1, Qt::AlignRight);
+ grid->addWidget(redlabel, 5, 1, Qt::AlignRight);
+ grid->addWidget(greenlabel, 6, 1, Qt::AlignRight);
+ grid->addWidget(bluelabel, 7, 1, Qt::AlignRight);
+ grid->addWidget(gctrl, 1, 2);
+ grid->addWidget(rgctrl, 5, 2);
+ grid->addWidget(ggctrl, 6, 2);
+ grid->addWidget(bgctrl, 7, 2);
+
+ topLayout->addLayout(grid);
+
+ //Options
+ QHBox *options = new QHBox(this);
+
+ xf86cfgbox = new QCheckBox( i18n("Save settings to XF86Config"), options );
+ connect(xf86cfgbox, SIGNAL(clicked()), SLOT(changeConfig()));
+
+ syncbox = new QCheckBox( i18n("Sync screens"), options );
+ connect(syncbox, SIGNAL(clicked()), SLOT(SyncScreens()));
+ connect(syncbox, SIGNAL(clicked()), SLOT(Changed()));
+
+ screenselect = new QComboBox( options );
+ for ( int i = 0; i < ScreenCount; i++ )
+ screenselect->insertItem( i18n("Screen %1").arg(i+1) );
+ screenselect->setCurrentItem(currentScreen);
+ connect(screenselect, SIGNAL(activated(int)), SLOT(changeScreen(int)));
+
+ options->setSpacing( 10 );
+ options->setStretchFactor( xf86cfgbox, 10 );
+ options->setStretchFactor( syncbox, 1 );
+ options->setStretchFactor( screenselect, 1 );
+
+ topLayout->addWidget(options);
+ }
+ else {
+ QLabel *error = new QLabel(this);
+ error->setText(i18n("Gamma correction is not supported by your"
+ " graphics hardware or driver."));
+ error->setAlignment(AlignCenter);
+ topLayout->addWidget(error);
+ }
+}
+
+void KGamma::load() {
+ load( false );
+}
+
+/** Restore latest saved gamma values */
+void KGamma::load(bool useDefaults) {
+ if (GammaCorrection) {
+ KConfig *config = new KConfig("kgammarc");
+
+ config->setReadDefaults( useDefaults );
+
+ config->setGroup("ConfigFile");
+
+ // save checkbox status
+ if ( xf86cfgbox->isChecked() ) config->writeEntry("use", "XF86Config");
+ else config->writeEntry("use", "kgammarc");
+
+ // load syncbox status
+ config->setGroup("SyncBox");
+ if ( config->readEntry("sync") == "yes" ) syncbox->setChecked(true);
+ else syncbox->setChecked(false);
+
+ config->sync();
+ delete config;
+
+ for (int i = 0; i < ScreenCount; i++) {
+ xv->setScreen(i);
+ if (rgamma[i] == ggamma[i] && rgamma[i] == bgamma[i])
+ if (i == currentScreen) gctrl->setGamma(rgamma[i]);
+ else xv->setGamma(XVidExtWrap::Value, rgamma[i].toFloat());
+ else {
+ if (i == currentScreen) {
+ rgctrl->setGamma(rgamma[i]);
+ ggctrl->setGamma(ggamma[i]);
+ bgctrl->setGamma(bgamma[i]);
+ gctrl->suspend();
+ }
+ else {
+ xv->setGamma(XVidExtWrap::Red, rgamma[i].toFloat());
+ xv->setGamma(XVidExtWrap::Green, ggamma[i].toFloat());
+ xv->setGamma(XVidExtWrap::Blue, bgamma[i].toFloat());
+ }
+ }
+ }
+ xv->setScreen(currentScreen);
+
+ emit changed(useDefaults);
+ }
+}
+
+void KGamma::save() {
+ if (GammaCorrection) {
+ for (int i = 0; i < ScreenCount; i++) {
+ xv->setScreen(i);
+ rgamma[i] = rgctrl->gamma(2);
+ ggamma[i] = ggctrl->gamma(2);
+ bgamma[i] = bgctrl->gamma(2);
+ }
+ xv->setScreen(currentScreen);
+
+ KConfig *config = new KConfig("kgammarc");
+ config->setGroup("SyncBox");
+ if ( syncbox->isChecked() ) config->writeEntry("sync", "yes");
+ else config->writeEntry("sync", "no");
+
+ if ( !xf86cfgbox->isChecked() ) { //write gamma settings to the users config
+ for (int i = 0; i < ScreenCount; i++) {
+ config->setGroup( QString("Screen %1").arg(i) );
+ config->writeEntry("rgamma", rgamma[i]);
+ config->writeEntry("ggamma", ggamma[i]);
+ config->writeEntry("bgamma", bgamma[i]);
+ }
+ config->setGroup("ConfigFile");
+ config->writeEntry("use", "kgammarc");
+ }
+ else { // write gamma settings to section "Monitor" of XF86Config
+ config->setGroup("ConfigFile");
+ config->writeEntry("use", "XF86Config");
+
+ if ( !rootProcess->isRunning() ) {
+ QString Arguments = "xf86gammacfg ";
+ for (int i = 0; i < ScreenCount; i++)
+ Arguments += rgamma[assign[i]] + " " + ggamma[assign[i]] + " " + \
+ bgamma[assign[i]] + " ";
+ rootProcess->clearArguments();
+ *rootProcess << "kdesu" << Arguments;
+ rootProcess->start();
+ }
+ }
+ config->sync();
+ delete config;
+ saved = true;
+ emit changed(false);
+ }
+}
+
+void KGamma::defaults() {
+ load( true );
+}
+
+bool KGamma::loadSettings() {
+ KConfig *config = new KConfig("kgammarc");
+ config->setGroup("ConfigFile");
+ QString ConfigFile( config->readEntry("use") );
+ config->setGroup("SyncBox");
+ if ( config->readEntry("sync") == "yes" ) syncbox->setChecked(true);
+ delete config;
+
+ if ( ConfigFile == "XF86Config" ) { // parse XF86Config
+ xf86cfgbox->setChecked(true);
+ return( loadSystemSettings() );
+ }
+ else { //get gamma settings from user config
+ return( loadUserSettings() );
+ }
+}
+
+bool KGamma::loadUserSettings() {
+ KConfig *config = new KConfig("kgammarc");
+
+ for (int i = 0; i < ScreenCount; i++) {
+ config->setGroup(QString( "Screen %1" ).arg(i) );
+ rgamma[i] = config->readEntry("rgamma");
+ ggamma[i] = config->readEntry("ggamma");
+ bgamma[i] = config->readEntry("bgamma");
+ }
+ delete config;
+
+ return( validateGammaValues() );
+}
+
+bool KGamma::loadSystemSettings() {
+ QStringList Monitor, Screen, ScreenLayout, ScreenMonitor, Gamma;
+ QValueList<int> ScreenNr;
+ QString Section;
+ XF86ConfigPath Path;
+
+ QFile f( Path.get() );
+ if ( f.open(IO_ReadOnly) ) {
+ QTextStream t( &f );
+ QString s;
+ int sn = 0;
+ bool gm = false;
+
+ // Analyse Screen<->Monitor assignments of multi-head configurations
+ while ( !t.eof() ) {
+ s = (t.readLine()).simplifyWhiteSpace();
+ QStringList words = QStringList::split(' ', s);
+
+ if ( !words.empty() ) {
+ if ( words[0] == "Section" && words.size() > 1 ) {
+ if ( (Section = words[1]) == "\"Monitor\"" ) gm = false;
+ }
+ else if ( words[0] == "EndSection" ) {
+ if ( Section == "\"Monitor\"" && !gm ) {
+ Gamma << "";
+ gm = false;
+ }
+ Section = "";
+ }
+ else if ( words[0] == "Identifier" && words.size() > 1 ) {
+ if ( Section == "\"Monitor\"" ) Monitor << words[1];
+ else if ( Section == "\"Screen\"" ) Screen << words[1];
+ }
+ else if ( words[0] == "Screen" && words.size() > 1 ) {
+ if ( Section == "\"ServerLayout\"" ) {
+ bool ok;
+ int i = words[1].toInt(&ok);
+ if ( ok && words.size() > 2 ) {
+ ScreenNr << i;
+ ScreenLayout << words[2];
+ }
+ else {
+ ScreenNr << sn++;
+ ScreenLayout << words[1];
+ }
+ }
+ }
+ else if ( words[0] == "Monitor" && words.size() > 1 ) {
+ if ( Section == "\"Screen\"" )
+ ScreenMonitor << words[1];
+ }
+ else if ( words[0] == "Gamma" ) {
+ if ( Section == "\"Monitor\"" ) {
+ Gamma << s;
+ gm = true;
+ }
+ }
+ }
+ } // End while
+ f.close();
+
+ for ( int i = 0; i < ScreenCount; i++ ) {
+ for ( int j = 0; j < ScreenCount; j++ ) {
+ if ( ScreenLayout[i] == Screen[j] ) {
+ for ( int k = 0; k < ScreenCount; k++ ) {
+ if ( Monitor[k] == ScreenMonitor[j] )
+ assign[ScreenNr[i]] = k;
+ }
+ }
+ }
+ }
+
+ // Extract gamma values
+ for ( int i = 0; i < ScreenCount; i++) {
+ rgamma[i] = ggamma[i] = bgamma[i] = "";
+
+ QStringList words = QStringList::split(' ', Gamma[assign[i]]);
+ QStringList::ConstIterator it = words.begin();
+ if ( words.size() < 4 )
+ rgamma[i] = ggamma[i] = bgamma[i] = *(++it); // single gamma value
+ else {
+ rgamma[i] = *(++it); // eventually rgb gamma values
+ ggamma[i] = *(++it);
+ bgamma[i] = *(++it);
+ }
+ }
+
+ }
+ return( validateGammaValues() );
+}
+
+bool KGamma::validateGammaValues() {
+ bool rOk, gOk, bOk, result;
+
+ result = true;
+ for (int i = 0; i < ScreenCount; i++ ) {
+ rgamma[i].toFloat( &rOk );
+ ggamma[i].toFloat( &gOk );
+ bgamma[i].toFloat( &bOk );
+
+ if ( !(rOk && gOk && bOk) ) {
+ if ( rOk ) ggamma[i] = bgamma[i] = rgamma[i];
+ else result = false;
+ }
+ }
+ return(result);
+}
+
+void KGamma::changeConfig() {
+ bool Ok = false;
+
+ if ( xf86cfgbox->isChecked() ) Ok = loadSystemSettings();
+ else Ok = loadUserSettings();
+
+ if ( !Ok ) {
+ for (int i = 0; i < ScreenCount; i++ ) {
+ xv->setScreen(i);
+ rgamma[i].setNum(xv->getGamma(XVidExtWrap::Red), 'f', 2);
+ ggamma[i].setNum(xv->getGamma(XVidExtWrap::Green), 'f', 2);
+ bgamma[i].setNum(xv->getGamma(XVidExtWrap::Blue), 'f', 2);
+ }
+ xv->setScreen(currentScreen);
+ }
+ load();
+}
+
+void KGamma::SyncScreens() {
+ if ( syncbox->isChecked() ) {
+ float rg = xv->getGamma(XVidExtWrap::Red);
+ float gg = xv->getGamma(XVidExtWrap::Green);
+ float bg = xv->getGamma(XVidExtWrap::Blue);
+
+ for (int i = 0; i < ScreenCount; i++ ) {
+ if ( i != currentScreen ) {
+ xv->setScreen(i);
+ xv->setGamma(XVidExtWrap::Red, rg);
+ xv->setGamma(XVidExtWrap::Green, gg);
+ xv->setGamma(XVidExtWrap::Blue, bg);
+ }
+ }
+ xv->setScreen(currentScreen);
+ }
+}
+
+void KGamma::changeScreen(int sn) {
+ QString red, green, blue;
+
+ xv->setScreen(sn);
+ currentScreen = sn;
+
+ red.setNum(xv->getGamma(XVidExtWrap::Red), 'f', 2);
+ green.setNum(xv->getGamma(XVidExtWrap::Green), 'f', 2);
+ blue.setNum(xv->getGamma(XVidExtWrap::Blue), 'f', 2);
+
+ gctrl->setControl(red);
+ rgctrl->setControl(red);
+ ggctrl->setControl(green);
+ bgctrl->setControl(blue);
+ if (red != green || red != blue) gctrl->suspend();
+}
+
+int KGamma::buttons () {
+ return Default|Apply|Help;
+}
+
+QString KGamma::quickHelp() const
+{
+ return i18n("<h1>Monitor Gamma</h1> This is a tool for changing monitor gamma"
+ " correction. Use the four sliders to define the gamma correction either"
+ " as a single value, or separately for the red, green and blue components."
+ " You may need to correct the brightness and contrast settings of your"
+ " monitor for good results. The test images help you to find proper"
+ " settings.<br> You can save them system-wide to XF86Config (root access"
+ " is required for that) or to your own KDE settings. On multi head"
+ " systems you can correct the gamma values separately for all screens.");
+}
+
+
+// ------------------------------------------------------------------------
+
+extern "C"
+{
+ // Restore the user gamma settings
+ void init_kgamma()
+ {
+ bool ok;
+ XVidExtWrap xv(&ok);
+
+ if (ok) {
+ xv.setGammaLimits(0.4, 3.5);
+ float rgamma, ggamma, bgamma;
+ KConfig *config = new KConfig("kgammarc");
+
+ for (int i = 0; i < xv._ScreenCount(); i++) {
+ xv.setScreen(i);
+ config->setGroup( QString("Screen %1").arg(i) );
+
+ if ((rgamma = config->readEntry("rgamma").toFloat()))
+ xv.setGamma(XVidExtWrap::Red, rgamma);
+ if ((ggamma = config->readEntry("ggamma").toFloat()))
+ xv.setGamma(XVidExtWrap::Green, ggamma);
+ if ((bgamma = config->readEntry("bgamma").toFloat()))
+ xv.setGamma(XVidExtWrap::Blue, bgamma);
+ }
+ delete config;
+ }
+ }
+}
diff --git a/kgamma/kcmkgamma/kgamma.desktop b/kgamma/kcmkgamma/kgamma.desktop
new file mode 100644
index 00000000..5d4c3b05
--- /dev/null
+++ b/kgamma/kcmkgamma/kgamma.desktop
@@ -0,0 +1,129 @@
+[Desktop Entry]
+Comment=A monitor calibration tool
+Comment[ar]=أداة مراقبة وتعيير
+Comment[bg]=Калибриране на монитора
+Comment[bs]=Alat za kalibraciju monitora
+Comment[ca]=Una eina de calibració del monitor
+Comment[cs]=Nástroj pro kalibraci monitoru
+Comment[cy]=Erfyn graddnodi dangosydd
+Comment[da]=Et skærmkalibreringsværktøj
+Comment[de]=Ein Kalibrierungswerkzeug für Monitore
+Comment[el]=Ένα εργαλείο ρύθμισης της οθόνης
+Comment[eo]=Ekrankalibrilo
+Comment[es]=Una herramienta de calibración del monitor
+Comment[et]=Monitori kalibreerija
+Comment[eu]=Monitoreak kalibratzeko tresna
+Comment[fa]=ابزار درجه‌بندی نمایشگر
+Comment[fi]=Näytön asetustyökalu
+Comment[fr]=Outil de calibrage de moniteur
+Comment[gl]=Unha utilidade para calibrar o monitor
+Comment[hi]=मॉनीटर केलिब्रेशन औज़ार
+Comment[hu]=Monitorbeállító program
+Comment[is]=Tól til að stilla skjáinn
+Comment[it]=Calibrazione del monitor
+Comment[ja]=モニタ測定ツール
+Comment[kk]=Мониторды калибрлеу құралы
+Comment[km]=ឧបករណ៍​ក្រិត​របស់​ម៉ូនីទ័រ
+Comment[lt]=Monitoriaus kalibravimo įrankis
+Comment[ms]=Alat tentukur monitor
+Comment[nb]=Et verktøy for å kalibrere skjermen
+Comment[nds]=En Afstimmwarktüüch för Monitoren
+Comment[ne]=मोनिटर क्यालिब्रेसन उपकरण
+Comment[nl]=Gereedschap om de kleurweergave goed in te stellen
+Comment[nn]=Eit verktøy for å kalibrera skjermen
+Comment[pl]=Narzędzie do kalibracji monitora
+Comment[pt]=Ferramenta de calibração do monitor
+Comment[pt_BR]=Uma ferramenta de calibragem de monitor
+Comment[ro]=Un utilitar de calibrat monitorul
+Comment[ru]=Утилита для калибровки монитора
+Comment[sk]=Kalibračný nástroj pre monitor
+Comment[sl]=Kalibracijsko orodje za monitorje
+Comment[sr]=Алат за калибрацију монитора
+Comment[sr@Latn]=Alat za kalibraciju monitora
+Comment[sv]=Kalibreringsverktyg för skärmen
+Comment[ta]=திரை நிலைக்கருவி
+Comment[tg]=Утилита барои калибратсия кардани монитор
+Comment[th]=เครื่องมือปรับความเที่ยงตรงของจอภาพ
+Comment[tr]=Monitör kalibrasyon aracı
+Comment[uk]=Засіб для калібрування монітора
+Comment[zh_CN]=监视器校准工具
+Comment[zh_HK]=顯示器調校工具
+Comment[zh_TW]=監視器校準工具
+
+Name=Gamma
+Name[ar]=غاما
+Name[az]=Qamma
+Name[bg]=Гама
+Name[cs]=Gama
+Name[cy]=Gama
+Name[el]=Γάμμα
+Name[eo]=Gamo
+Name[fa]=گاما
+Name[ga]=Gáma
+Name[gl]=Gama
+Name[he]=גאמה
+Name[hr]=Gama
+Name[hu]=Gamma-korrekció
+Name[is]=Litatíðni (gamma)
+Name[kk]=Гамма
+Name[km]=ហ្គាម៉ា
+Name[ne]=गामा
+Name[pa]=ਗ਼ਾਮਾ
+Name[pt]=Gama
+Name[ru]=Гамма
+Name[sl]=Gama
+Name[sr]=Гама
+Name[sr@Latn]=Gama
+Name[ta]=காமா
+Name[tg]=Гамма
+Name[th]=แกมมา
+Name[uk]=Гама
+Name[uz@cyrillic]=Гамма
+Name[wa]=Gama
+Name[xh]=Unobumba wesithathu konoobumba besiGrike
+Name[zh_HK]=伽馬(Gamma)
+
+DocPath=kgamma
+Exec=kcmshell kgamma
+Icon=kgamma
+Keywords=KGamma, kgamma, Gamma, gamma
+Keywords[bg]=калибриране, гама, яркост, цвят, монитор, екран, KGamma, kgamma, Gamma, gamma
+Keywords[cs]=KGamma, kgamma, gama
+Keywords[de]=KGamma,kgamma,Gamma,gamma
+Keywords[el]=KGamma, kgamma, Γάμμα, γάμμα
+Keywords[ga]=KGamma, kgamma, Gamma, gamma, Gáma
+Keywords[gl]=KGamma, kgamma, Gamma, gamma, gama
+Keywords[he]=KGamma, kgamma, Gamma, gamma, גאמה
+Keywords[hi]=के-गामा,केगामा,गामा,गामा
+Keywords[hu]=KGamma,kgamma,gamma,gamma-korrekció
+Keywords[it]=KGamma,gamma
+Keywords[ja]=KGamma, kgamma, ガンマ, Gamma, gamma
+Keywords[km]=KGamma, kgamma,ហ្គ៉ាម៉ា
+Keywords[lt]=KGamma, kgamma, Gamma, gamma, gama
+Keywords[nds]=KGamma,kgamma,Gamma,gamma
+Keywords[ne]=के गामा, के गामा, गामा, गामा
+Keywords[nl]=KGamma,kgamma,Gamma,gamma,kleurweergave
+Keywords[nn]=KGamma,gamma
+Keywords[pl]=KGamma, kgamma, Gamma, gamma, jasność,ciemność,rozjaśnienie
+Keywords[pt]=kgamma, gama
+Keywords[pt_BR]=KGama, kgama, Gama, gama
+Keywords[ro]=KGamma,kgamma,gama,gamma
+Keywords[ru]=KGamma,kgamma,Gamma,gamma,гамма,монитор
+Keywords[sk]=KGamma, kgamma, gamma
+Keywords[sl]=KGamma,kgamma,Gama,gama
+Keywords[sr]=KGamma, kgamma, Gamma, gamma, гама
+Keywords[sr@Latn]=KGamma, kgamma, Gamma, gamma, gama
+Keywords[ta]=கேகாமா, கேகாமா, காமா, காமா
+Keywords[tg]=KGamma,kgamma,Gamma,gamma,гамма,монитор
+Keywords[uk]=KGamma, kgamma, Gamma, gamma, гама, яскравість
+Keywords[uz@cyrillic]=KGamma, kgamma, Гамма, гамма
+Keywords[wa]=KGamma, kgamma, Gama, gama
+Keywords[zh_CN]=KGamma, kgamma, Gamma, gamma,伽玛
+Type=Application
+X-KDE-Init=kgamma
+X-KDE-FactoryName=kgamma
+X-KDE-Library=kgamma
+X-KDE-ModuleType=Library
+X-KDE-Test-Module=true
+NoDisplay=true
+Categories=Qt;KDE;Settings;X-KDE-settings-peripherals;
diff --git a/kgamma/kcmkgamma/kgamma.h b/kgamma/kcmkgamma/kgamma.h
new file mode 100644
index 00000000..b347e2a1
--- /dev/null
+++ b/kgamma/kcmkgamma/kgamma.h
@@ -0,0 +1,78 @@
+/***************************************************************************
+ kgamma.h - description
+ -------------------
+ begin : Sun Dec 16 13:52:24 CET 2001
+ copyright : (C) 2001 by Michael v.Ostheim
+ email : MvOstheim@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+#ifndef KGAMMA_H_
+#define KGAMMA_H_
+
+#include <kcmodule.h>
+
+class GammaCtrl;
+class QCheckBox;
+class QComboBox;
+class XVidExtWrap;
+class KProcess;
+
+class KGamma: public KCModule
+{
+ Q_OBJECT
+ public:
+ KGamma(QWidget *parent, const char *name, const QStringList&);
+ virtual ~KGamma();
+
+ void load();
+ void load(bool useDefaults);
+ void save();
+ void defaults();
+ int buttons();
+ QString quickHelp() const;
+
+ protected: // Protected methods
+ /** The user interface */
+ void setupUI();
+ /** Decides if to load settings from user or system config */
+ bool loadSettings();
+ /** Load settings from kgammarc */
+ bool loadUserSettings();
+ /** Load settings from XF86Config */
+ bool loadSystemSettings();
+ /** Validate the loaded gamma values */
+ bool validateGammaValues();
+
+ private slots:
+ /** Called if the user changesd something */
+ void Changed() { emit changed(true); }
+ /** Called if the user marked or unmarked the XF86Config checkbox */
+ void changeConfig();
+ /** Called if the user marked or unmarked the sync screen checkbox */
+ void SyncScreens();
+ /** Called if the user chooses a new screen */
+ void changeScreen(int sn);
+
+ private:
+ bool saved, GammaCorrection;
+ int ScreenCount, currentScreen;
+ QStringList rgamma, ggamma, bgamma;
+ QValueList<int> assign;
+ QValueList<float> rbak, gbak, bbak;
+ GammaCtrl *gctrl, *rgctrl, *ggctrl, *bgctrl;
+ QCheckBox *xf86cfgbox, *syncbox;
+ QComboBox *screenselect;
+ KProcess *rootProcess;
+ XVidExtWrap *xv;
+};
+
+#endif
+
diff --git a/kgamma/kcmkgamma/pics/Makefile.am b/kgamma/kcmkgamma/pics/Makefile.am
new file mode 100644
index 00000000..14dd5857
--- /dev/null
+++ b/kgamma/kcmkgamma/pics/Makefile.am
@@ -0,0 +1,7 @@
+
+img_DATA = background.png cmyscale.png darkgrey.png greyscale.png lightgrey.png midgrey.png \
+ rgbscale.png
+imgdir = $(kde_datadir)/kgamma/pics
+
+KDE_ICON = kgamma
+
diff --git a/kgamma/kcmkgamma/pics/background.png b/kgamma/kcmkgamma/pics/background.png
new file mode 100644
index 00000000..01797213
--- /dev/null
+++ b/kgamma/kcmkgamma/pics/background.png
Binary files differ
diff --git a/kgamma/kcmkgamma/pics/cmyscale.png b/kgamma/kcmkgamma/pics/cmyscale.png
new file mode 100644
index 00000000..e30700bc
--- /dev/null
+++ b/kgamma/kcmkgamma/pics/cmyscale.png
Binary files differ
diff --git a/kgamma/kcmkgamma/pics/darkgrey.png b/kgamma/kcmkgamma/pics/darkgrey.png
new file mode 100644
index 00000000..221d65e4
--- /dev/null
+++ b/kgamma/kcmkgamma/pics/darkgrey.png
Binary files differ
diff --git a/kgamma/kcmkgamma/pics/greyscale.png b/kgamma/kcmkgamma/pics/greyscale.png
new file mode 100644
index 00000000..8532c3ea
--- /dev/null
+++ b/kgamma/kcmkgamma/pics/greyscale.png
Binary files differ
diff --git a/kgamma/kcmkgamma/pics/hi16-app-kgamma.png b/kgamma/kcmkgamma/pics/hi16-app-kgamma.png
new file mode 100644
index 00000000..de14649c
--- /dev/null
+++ b/kgamma/kcmkgamma/pics/hi16-app-kgamma.png
Binary files differ
diff --git a/kgamma/kcmkgamma/pics/hi32-app-kgamma.png b/kgamma/kcmkgamma/pics/hi32-app-kgamma.png
new file mode 100644
index 00000000..c5f605df
--- /dev/null
+++ b/kgamma/kcmkgamma/pics/hi32-app-kgamma.png
Binary files differ
diff --git a/kgamma/kcmkgamma/pics/hi48-app-kgamma.png b/kgamma/kcmkgamma/pics/hi48-app-kgamma.png
new file mode 100644
index 00000000..19fd51e7
--- /dev/null
+++ b/kgamma/kcmkgamma/pics/hi48-app-kgamma.png
Binary files differ
diff --git a/kgamma/kcmkgamma/pics/lightgrey.png b/kgamma/kcmkgamma/pics/lightgrey.png
new file mode 100644
index 00000000..650603c8
--- /dev/null
+++ b/kgamma/kcmkgamma/pics/lightgrey.png
Binary files differ
diff --git a/kgamma/kcmkgamma/pics/midgrey.png b/kgamma/kcmkgamma/pics/midgrey.png
new file mode 100644
index 00000000..5b22f4c5
--- /dev/null
+++ b/kgamma/kcmkgamma/pics/midgrey.png
Binary files differ
diff --git a/kgamma/kcmkgamma/pics/rgbscale.png b/kgamma/kcmkgamma/pics/rgbscale.png
new file mode 100644
index 00000000..5e9be6d9
--- /dev/null
+++ b/kgamma/kcmkgamma/pics/rgbscale.png
Binary files differ
diff --git a/kgamma/kcmkgamma/xf86configpath.cpp b/kgamma/kcmkgamma/xf86configpath.cpp
new file mode 100644
index 00000000..e6f7163b
--- /dev/null
+++ b/kgamma/kcmkgamma/xf86configpath.cpp
@@ -0,0 +1,56 @@
+/***************************************************************************
+ xf86configpath.cpp - description
+ -------------------
+ begin : Mon Dec 30 2002
+ copyright : (C) 2002 by Michael v.Ostheim
+ email : ostheimm@users.berlios.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <vector>
+
+#include "xf86configpath.h"
+
+using namespace std;
+
+XF86ConfigPath::XF86ConfigPath(){
+ vector <string> searchPaths;
+ searchPaths.push_back("/etc/X11/XF86Config-4");
+ searchPaths.push_back("/etc/X11/XF86Config");
+ searchPaths.push_back("/etc/XF86Config");
+ searchPaths.push_back("/usr/X11R6/etc/X11/XF86Config-4");
+ searchPaths.push_back("/usr/X11R6/etc/X11/XF86Config");
+ searchPaths.push_back("/usr/X11R6/lib/X11/XF86Config-4");
+ searchPaths.push_back("/usr/X11R6/lib/X11/XF86Config");
+
+ searchPaths.push_back("/etc/X11/xorg.conf-4");
+ searchPaths.push_back("/etc/X11/xorg.conf");
+ searchPaths.push_back("/etc/xorg.conf");
+ searchPaths.push_back("/usr/X11R6/etc/X11/xorg.conf-4");
+ searchPaths.push_back("/usr/X11R6/etc/X11/xorg.conf");
+ searchPaths.push_back("/usr/X11R6/lib/X11/xorg.conf-4");
+ searchPaths.push_back("/usr/X11R6/lib/X11/xorg.conf");
+
+ vector<string>::iterator it = searchPaths.begin();
+ for (; it != searchPaths.end(); ++it )
+ if ( !access( (Path = *it).c_str(), F_OK ) ) break;
+}
+
+XF86ConfigPath::~XF86ConfigPath(){
+}
+
+/** Returns path */
+const char* XF86ConfigPath::get(){
+ return( Path.c_str() );
+}
diff --git a/kgamma/kcmkgamma/xf86configpath.h b/kgamma/kcmkgamma/xf86configpath.h
new file mode 100644
index 00000000..88f7afa4
--- /dev/null
+++ b/kgamma/kcmkgamma/xf86configpath.h
@@ -0,0 +1,42 @@
+/***************************************************************************
+ xf86configpath.h - description
+ -------------------
+ begin : Mon Dec 30 2002
+ copyright : (C) 2002 by Michael v.Ostheim
+ email : ostheimm@users.berlios.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef XF86CONFIGPATH_H
+#define XF86CONFIGPATH_H
+
+#include <string>
+
+/**Search for XF86Config or XF86Config-4 which can be located at different
+ places.
+ *@author Michael v.Ostheim
+ */
+
+class XF86ConfigPath {
+
+public:
+ XF86ConfigPath();
+ ~XF86ConfigPath();
+
+ /** Returns Path variable */
+ const char* get();
+
+private: // Private attributes
+ /** Contains the path of XF86Config file */
+ std::string Path;
+};
+
+#endif
diff --git a/kgamma/kcmkgamma/xvidextwrap.cpp b/kgamma/kcmkgamma/xvidextwrap.cpp
new file mode 100644
index 00000000..9d8136d9
--- /dev/null
+++ b/kgamma/kcmkgamma/xvidextwrap.cpp
@@ -0,0 +1,170 @@
+/***************************************************************************
+ xvidextwrap.cpp - description
+ -------------------
+ begin : Sat Jan 5 2002
+ copyright : (C) 2002 by Michael v.Ostheim
+ email : MvOstheim@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+#include <X11/Xos.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/extensions/xf86vmode.h>
+
+#include <stdlib.h>
+#include <iostream>
+#include <fstream>
+
+#include <vector>
+#include <string>
+
+#include <config.h>
+
+#ifdef HAVE_SSTREAM
+#include <sstream>
+#else
+#include <strstream.h>
+#define istringstream istrstream
+#endif
+
+#include <kdebug.h>
+
+#include "xf86configpath.h"
+#include "xvidextwrap.h"
+
+using namespace std;
+
+
+XVidExtWrap::XVidExtWrap(bool* OK, const char* displayname) {
+ if ((dpy = XOpenDisplay(displayname))) {
+ screen = DefaultScreen(dpy);
+ setGammaLimits(0.1, 10.0);
+ *OK = true;
+ }
+ else {
+ kdDebug() << "KGamma: unable to open display " << displayname << endl;
+ *OK = false;
+ }
+}
+
+XVidExtWrap::~XVidExtWrap() {
+ if (dpy) XCloseDisplay(dpy);
+}
+
+int XVidExtWrap::_DefaultScreen() {
+ return DefaultScreen(dpy);
+}
+
+/** We have to parse XF86Config to get the number of screens, because */
+/** ScreenCount() from X11/Xlib.h does not count correctly with xinerama */
+int XVidExtWrap::_ScreenCount() {
+ int count = 0;
+ bool section = false;
+ XF86ConfigPath Path;
+
+ std::ifstream in( Path.get() );
+
+ if ( in.is_open() ) {
+ std::string s, buf;
+ std::vector<string> words;
+
+ while (getline(in, s,'\n')) {
+ words.clear();
+ istringstream ss(s.c_str());
+ while (ss >> buf) words.push_back(buf); // Split "s" into words
+
+ if ( !words.empty() ) {
+ if ( words[0] == "Section" && words.size() > 1 ) {
+ if ( words[1] == "\"ServerLayout\"" ) section = true;
+ }
+ else if ( words[0] == "EndSection" )
+ section = false;
+ if ( section && words[0] == "Screen" ) ++count;
+ }
+ } //end while
+ in.close();
+
+ }
+
+ if ( !count ) count = 1; //If failed,fill count with a valid value;
+
+ return( count );
+}
+
+const char* XVidExtWrap::DisplayName() {
+ return DisplayString(dpy);
+}
+
+void XVidExtWrap::setGamma(int channel, float gam, bool* OK) {
+ XF86VidModeGamma gamma;
+
+ if ( gam >= mingamma && gam <= maxgamma ) {
+ if (!XF86VidModeGetGamma(dpy, screen, &gamma)) {
+ kdDebug() << "KGamma: Unable to query gamma correction" << endl;
+ if ( OK ) *OK = false;
+ }
+ else {
+ switch (channel) {
+ case Value:
+ gamma.red = gam;
+ gamma.green = gam;
+ gamma.blue = gam; break;
+ case Red:
+ gamma.red = gam; break;
+ case Green:
+ gamma.green = gam; break;
+ case Blue:
+ gamma.blue = gam;
+ };
+ if (!XF86VidModeSetGamma(dpy, screen, &gamma)) {
+ kdDebug() << "KGamma: Unable to set gamma correction" << endl;
+ if ( OK ) *OK = false;
+ }
+ else {
+ XFlush(dpy);
+ if ( OK ) *OK = true;
+ }
+ }
+ }
+}
+
+float XVidExtWrap::getGamma(int channel, bool* OK) {
+ XF86VidModeGamma gamma;
+ float gam = 0;
+
+ if (!XF86VidModeGetGamma(dpy, screen, &gamma)) {
+ kdDebug() << "KGamma: Unable to query gamma correction" << endl;
+ if ( OK ) *OK = false;
+ }
+ else {
+ switch (channel) {
+ case Value:
+ gam = gamma.red; break;
+ case Red:
+ gam = gamma.red; break;
+ case Green:
+ gam = gamma.green; break;
+ case Blue:
+ gam = gamma.blue;
+ };
+ if ( OK ) *OK = true;
+ }
+ return(gam);
+}
+
+void XVidExtWrap::setGammaLimits( float min, float max ) {
+ mingamma = (min < 0.1) ? 0.1 : min;
+ maxgamma = (max > 10.0) ? 10.0 : max;
+}
+
+#ifdef istringstream
+#undef istringstream
+#endif
diff --git a/kgamma/kcmkgamma/xvidextwrap.h b/kgamma/kcmkgamma/xvidextwrap.h
new file mode 100644
index 00000000..20ae4310
--- /dev/null
+++ b/kgamma/kcmkgamma/xvidextwrap.h
@@ -0,0 +1,59 @@
+/***************************************************************************
+ xvidextwrap.h - description
+ -------------------
+ begin : Sat Jan 5 2002
+ copyright : (C) 2002 by Michael v.Ostheim
+ email : MvOstheim@web.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef XVIDEXTWRAP_H
+#define XVIDEXTWRAP_H
+
+struct _XDisplay;
+
+/**A wrapper for XF86VidMode Extension
+ *@author Michael v.Ostheim
+ */
+
+class XVidExtWrap {
+
+ public:
+
+ enum GammaChannel { Value = 0, Red = 1, Green = 2, Blue = 3 };
+ XVidExtWrap(bool *OK, const char* displayname = NULL);
+ ~XVidExtWrap();
+
+ /** Returns the default screen */
+ int _DefaultScreen();
+ /** Returns the number of screens (extracted from XF86Config) */
+ int _ScreenCount();
+ /** Returns the displayname */
+ const char* DisplayName();
+ /** Sets the screen actions are take effect */
+ void setScreen( int scrn ) { screen = scrn; };
+ /** Returns the current screen */
+ int getScreen() { return screen; };
+ /** Sets the gamma value on the current screen */
+ void setGamma( int channel, float gam, bool *OK = NULL );
+ /** Gets the gamma value of the current screen */
+ float getGamma( int channel, bool *OK = NULL );
+ /** Limits the possible gamma values (default 0.1-10.0) */
+ void setGammaLimits( float min, float max );
+
+ private:
+ float mingamma, maxgamma;
+ int screen;
+ Display* dpy;
+};
+
+#endif
+