Commit 402cf1d2 authored by Alexander Lohnau's avatar Alexander Lohnau 💬
Browse files

Run clang-format

If you want git blame to ignore formatting revisions run:
git config blame.ignoreRevsFile .git-blame-ignore-revs
parent b37b6ffa
......@@ -4,47 +4,51 @@
* SPDX-FileCopyrightText: 2003 Michael v.Ostheim <ostheimm@users.berlios.de>
*/
#include <QString>
#include <QDebug>
#include <QFontMetrics>
#include <QLabel>
#include <QFrame>
#include <QDebug>
#include <QLabel>
#include <QString>
#include "displaynumber.h"
DisplayNumber::DisplayNumber(QWidget *parent, int digits, int prec)
: QLabel(parent) {
setPrecision(prec);
setWidth(digits);
DisplayNumber::DisplayNumber(QWidget *parent, int digits, int prec)
: QLabel(parent)
{
setPrecision(prec);
setWidth(digits);
setFrameStyle(QFrame::Panel | QFrame::Sunken);
setBackgroundRole(QPalette::Base);
setAlignment(Qt::AlignCenter);
setFocusPolicy(Qt::NoFocus);
setFrameStyle(QFrame::Panel | QFrame::Sunken);
setBackgroundRole(QPalette::Base);
setAlignment(Qt::AlignCenter);
setFocusPolicy(Qt::NoFocus);
}
DisplayNumber::~DisplayNumber(){
DisplayNumber::~DisplayNumber()
{
}
void DisplayNumber::setFont( const QFont & f ) {
QLabel::setFont(f);
setWidth(dg);
void DisplayNumber::setFont(const QFont &f)
{
QLabel::setFont(f);
setWidth(dg);
}
void DisplayNumber::setWidth(int digits) {
QFontMetrics fm(font());
QString s(QStringLiteral("0123456789.+-"));
int width = 0, charWidth=0;
void DisplayNumber::setWidth(int digits)
{
QFontMetrics fm(font());
QString s(QStringLiteral("0123456789.+-"));
int width = 0, charWidth = 0;
for (int i = 0; i < 11; i++, width = fm.boundingRect(s[i]).width())
charWidth = (width > charWidth) ? width : charWidth;
for (int i = 0; i < 11; i++, width = fm.boundingRect(s[i]).width())
charWidth = (width > charWidth) ? width : charWidth;
dg = digits;
setMinimumWidth( dg * charWidth + charWidth/2 );
dg = digits;
setMinimumWidth(dg * charWidth + charWidth / 2);
}
void DisplayNumber::setNum(double num) {
QString text;
setText(text.setNum(num, 'f', precision));
void DisplayNumber::setNum(double num)
{
QString text;
setText(text.setNum(num, 'f', precision));
}
......@@ -10,21 +10,25 @@
#include <qlabel.h>
/**
*@author Michael v.Ostheim
*/
*@author Michael v.Ostheim
*/
class DisplayNumber : public QLabel
{
Q_OBJECT
public:
explicit DisplayNumber(QWidget *parent = nullptr, int digits = 0, int prec = 0);
~DisplayNumber() override;
void setFont(const QFont &f);
void setNum(double num);
void setWidth(int digits);
void setPrecision(int prec)
{
precision = prec;
}
class DisplayNumber : public QLabel {
Q_OBJECT
public:
explicit DisplayNumber(QWidget *parent=nullptr, int digits=0, int prec=0);
~DisplayNumber() override;
void setFont( const QFont & f );
void setNum(double num);
void setWidth(int digits);
void setPrecision(int prec) { precision = prec; }
private:
int dg, precision;
int dg, precision;
};
#endif
......@@ -11,42 +11,39 @@
#include <qlineedit.h>
#include <qstring.h>
#include "xvidextwrap.h"
#include "displaynumber.h"
#include "xvidextwrap.h"
GammaCtrl::GammaCtrl(QWidget *parent, XVidExtWrap *xvid, int channel, \
const QString& mingamma, const QString& maxgamma, const QString& setgamma)
: QWidget(parent)
GammaCtrl::GammaCtrl(QWidget *parent, XVidExtWrap *xvid, int channel, const QString &mingamma, const QString &maxgamma, const QString &setgamma)
: QWidget(parent)
{
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;
QHBoxLayout *layout = new QHBoxLayout(this);
slider = new QSlider(Qt::Horizontal, this);
slider->setTickPosition(QSlider::TicksBelow);
slider->setRange(0, maxslider);
slider->setTickInterval(2);
slider->setValue(setslider);
layout->addWidget(slider);
connect(slider, SIGNAL(valueChanged(int)), SLOT(setGamma(int)));
connect(slider, &QAbstractSlider::sliderPressed, this, &GammaCtrl::pressed);
textfield = new DisplayNumber(this, 4, 2);
textfield->setText(setgamma);
layout->addWidget(textfield);
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;
QHBoxLayout *layout = new QHBoxLayout(this);
slider = new QSlider(Qt::Horizontal, this);
slider->setTickPosition(QSlider::TicksBelow);
slider->setRange(0, maxslider);
slider->setTickInterval(2);
slider->setValue(setslider);
layout->addWidget(slider);
connect(slider, SIGNAL(valueChanged(int)), SLOT(setGamma(int)));
connect(slider, &QAbstractSlider::sliderPressed, this, &GammaCtrl::pressed);
textfield = new DisplayNumber(this, 4, 2);
textfield->setText(setgamma);
layout->addWidget(textfield);
}
GammaCtrl::~GammaCtrl()
......@@ -54,73 +51,79 @@ 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);
}
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;
void GammaCtrl::setControl(const QString &gamma)
{
int sliderpos;
sliderpos = (int)( ( gamma.toDouble() - mgamma.toDouble() + 0.0005 ) * 20 );
setCtrl(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);
QString GammaCtrl::gamma(int prec)
{
QString gammatext;
gammatext.setNum(xv->getGamma(gchannel) + 0.0005, 'f', prec);
return(gammatext);
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);
}
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));
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);
}
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());
}
void GammaCtrl::pressed()
{
if (suspended) {
suspended = false;
textfield->setDisabled(false);
changed = true;
setGamma(slider->value());
}
}
......@@ -15,26 +15,32 @@ class QString;
class DisplayNumber;
class XVidExtWrap;
class GammaCtrl : public QWidget {
Q_OBJECT
public:
class GammaCtrl : public QWidget
{
Q_OBJECT
public:
/** construktor */
explicit GammaCtrl(QWidget *parent=nullptr, XVidExtWrap *xvid=nullptr, int channel=0,
const QString& mingamma=QStringLiteral("0.40"), const QString& maxgamma=QStringLiteral("3.50"),
const QString& setgamma=QStringLiteral("1.00"));
explicit GammaCtrl(QWidget *parent = nullptr,
XVidExtWrap *xvid = nullptr,
int channel = 0,
const QString &mingamma = QStringLiteral("0.40"),
const QString &maxgamma = QStringLiteral("3.50"),
const QString &setgamma = QStringLiteral("1.00"));
/** destruktor */
~GammaCtrl() override;
/** Return the current gamma value with precision prec */
QString gamma(int);
/** Set gamma, slider and textfield */
void setGamma(const QString&);
void setGamma(const QString &);
/** Set slider and textfield */
void setControl(const QString&);
void setControl(const QString &);
/** Disable the slider */
void disableSlider() { slider->setDisabled(true);}
void disableSlider()
{
slider->setDisabled(true);
}
private:
private:
QString mgamma;
QSlider *slider;
DisplayNumber *textfield;
......@@ -43,11 +49,11 @@ class GammaCtrl : public QWidget {
double ming;
XVidExtWrap *xv;
public Q_SLOTS:
public Q_SLOTS:
/** Disable textfield */
void suspend();
protected Q_SLOTS:
protected Q_SLOTS:
/** Set slider and textfield */
void setCtrl(int);
/** Set gamma and textfield */
......@@ -55,7 +61,7 @@ class GammaCtrl : public QWidget {
/** Change status of GammaCtrl when pressed */
void pressed();
Q_SIGNALS:
Q_SIGNALS:
/** Gamma change signal */
void gammaChanged(int);
};
......
This diff is collapsed.
......@@ -8,7 +8,7 @@
#define KGAMMA_H_
#include <KCModule>
//Added by qt3to4:
// Added by qt3to4:
#include <QList>
class GammaCtrl;
......@@ -17,53 +17,55 @@ class QComboBox;
class QProcess;
class XVidExtWrap;
class KGamma: public KCModule
class KGamma : public KCModule
{
Q_OBJECT
public:
KGamma(QWidget* parent_P, const QVariantList &args );
~KGamma() override;
Q_OBJECT
public:
KGamma(QWidget *parent_P, const QVariantList &args);
~KGamma() override;
void load() override;
void save() override;
void defaults() override;
int buttons();
QString quickHelp() const override;
void load() override;
void save() override;
void defaults() override;
int buttons();
QString quickHelp() const override;
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();
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 Q_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 Q_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;
QList<int> assign;
QList<float> rbak, gbak, bbak;
GammaCtrl *gctrl, *rgctrl, *ggctrl, *bgctrl;
QCheckBox *xf86cfgbox, *syncbox;
QComboBox *screenselect;
QProcess *rootProcess;
XVidExtWrap *xv;
private:
bool saved, GammaCorrection;
int ScreenCount, currentScreen;
QStringList rgamma, ggamma, bgamma;
QList<int> assign;
QList<float> rbak, gbak, bbak;
GammaCtrl *gctrl, *rgctrl, *ggctrl, *bgctrl;
QCheckBox *xf86cfgbox, *syncbox;
QComboBox *screenselect;
QProcess *rootProcess;
XVidExtWrap *xv;
};
#endif
......@@ -13,8 +13,9 @@
using namespace std;
XF86ConfigPath::XF86ConfigPath(){
vector <string> searchPaths;
XF86ConfigPath::XF86ConfigPath()
{
vector<string> searchPaths;
searchPaths.push_back("/etc/X11/XF86Config-4");
searchPaths.push_back("/etc/X11/XF86Config");
searchPaths.push_back("/etc/XF86Config");
......@@ -32,14 +33,17 @@ XF86ConfigPath::XF86ConfigPath(){
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;
for (; it != searchPaths.end(); ++it)
if (!access((Path = *it).c_str(), F_OK))
break;
}
XF86ConfigPath::~XF86ConfigPath(){
XF86ConfigPath::~XF86ConfigPath()
{
}
/** Returns path */
const char* XF86ConfigPath::get(){
return( Path.c_str() );
const char *XF86ConfigPath::get()
{
return (Path.c_str());
}
......@@ -14,18 +14,18 @@
*@author Michael v.Ostheim
*/
class XF86ConfigPath {
public:
XF86ConfigPath();
~XF86ConfigPath();
class XF86ConfigPath
{
public:
XF86ConfigPath();
~XF86ConfigPath();
/** Returns Path variable */
const char* get();
/** Returns Path variable */
const char *get();
private: // Private attributes
/** Contains the path of XF86Config file */
std::string Path;
/** Contains the path of XF86Config file */
std::string Path;
};
#endif
......@@ -6,12 +6,12 @@
#include <QDebug>
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <iostream>
#include <stdlib.h>
#include <vector>
#include <string>
#include <vector>
#include "config-kgamma.h"
......@@ -24,137 +24,153 @@
#include "xf86configpath.h"
#include <X11/Xos.h>
#include <X11/Xlib.h>
#include <X11/Xos.h>
#include <X11/extensions/xf86vmode.h>
// #include <fixx11h.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 {
qDebug() << "KGamma: unable to open display " << displayname;
*OK = false;
}
XVidExtWrap::XVidExtWrap(bool *OK, const char *displayname)
{
if ((dpy = XOpenDisplay(displayname))) {
screen = DefaultScreen(dpy);
setGammaLimits(0.1, 10.0);
*OK = true;
} else {
qDebug() << "KGamma: unable to open display " << displayname;
*OK = false;
}
}
XVidExtWrap::~XVidExtWrap() {
if (dpy) XCloseDisplay(dpy);
XVidExtWrap::~XVidExtWrap()
{
if (dpy)
XCloseDisplay(dpy);
}