kdeui: format and indent

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2023-06-29 05:53:43 +03:00
parent 6a60f0d43a
commit 01d26adc48
2 changed files with 158 additions and 150 deletions

View file

@ -200,7 +200,7 @@ class KTipDialog::Private
static KTipDialog *mInstance; static KTipDialog *mInstance;
}; };
KTipDialog *KTipDialog::Private::mInstance = 0; KTipDialog *KTipDialog::Private::mInstance = nullptr;
void KTipDialog::Private::_k_prevTip() void KTipDialog::Private::_k_prevTip()
{ {
@ -216,110 +216,111 @@ void KTipDialog::Private::_k_nextTip()
.arg( i18n( database->tip().toUtf8() ) ) ); .arg( i18n( database->tip().toUtf8() ) ) );
} }
void KTipDialog::Private::_k_showOnStart( bool on ) void KTipDialog::Private::_k_showOnStart(bool on)
{ {
parent->setShowOnStart( on ); parent->setShowOnStart(on);
} }
KTipDialog::KTipDialog( KTipDatabase *database, QWidget *parent ) KTipDialog::KTipDialog(KTipDatabase *database, QWidget *parent)
: KDialog( parent ), : KDialog(parent),
d( new Private( this ) ) d(new Private(this))
{ {
setButtons( KDialog::None ); setButtons(KDialog::None);
setCaption( i18n( "Tip of the Day" ) ); setCaption(i18n("Tip of the Day"));
/** /**
* Parent is 0L when TipDialog is used as a mainWidget. This should * Parent is 0L when TipDialog is used as a mainWidget. This should
* be the case only in ktip, so let's use the ktip layout. * be the case only in ktip, so let's use the ktip layout.
*/ */
bool isTipDialog = (parent != 0); bool isTipDialog = (parent != nullptr);
d->database = database; d->database = database;
setWindowIcon(KIcon("ktip")); setWindowIcon(KIcon("ktip"));
QWidget *widget = new QWidget( this ); QWidget *widget = new QWidget(this);
setMainWidget( widget ); setMainWidget(widget);
QVBoxLayout *mainLayout = new QVBoxLayout( widget ); QVBoxLayout *mainLayout = new QVBoxLayout(widget);
mainLayout->setMargin( 0 ); mainLayout->setMargin(0);
if ( isTipDialog ) { if (isTipDialog) {
QLabel *titleLabel = new QLabel( this ); QLabel *titleLabel = new QLabel(this);
titleLabel->setText( i18n( "Did you know...?\n" ) ); titleLabel->setText(i18n("Did you know...?\n" ) );
titleLabel->setFont( QFont( KGlobalSettings::generalFont().family(), 20, QFont::Bold ) ); titleLabel->setFont(QFont(KGlobalSettings::generalFont().family(), 20, QFont::Bold));
titleLabel->setAlignment( Qt::AlignCenter ); titleLabel->setAlignment(Qt::AlignCenter);
mainLayout->addWidget( titleLabel ); mainLayout->addWidget(titleLabel);
} }
QHBoxLayout *browserLayout = new QHBoxLayout(); QHBoxLayout *browserLayout = new QHBoxLayout();
mainLayout->addLayout( browserLayout ); mainLayout->addLayout(browserLayout);
d->tipText = new QTextBrowser( this ); d->tipText = new QTextBrowser(this);
d->tipText->setOpenExternalLinks( true ); d->tipText->setOpenExternalLinks(true);
d->tipText->setWordWrapMode( QTextOption::WrapAtWordBoundaryOrAnywhere ); d->tipText->setWordWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
QStringList paths; QStringList paths;
paths << KGlobal::dirs()->resourceDirs( "icon" ) paths << KGlobal::dirs()->resourceDirs("icon")
<< KGlobal::dirs()->findResourceDir( "data", "kdewizard/pics" ) + "kdewizard/pics/"; << KGlobal::dirs()->findResourceDir("data", "kdewizard/pics") + "kdewizard/pics/";
d->tipText->setSearchPaths( paths ); d->tipText->setSearchPaths(paths);
d->tipText->setFrameStyle( QFrame::NoFrame ); d->tipText->setFrameStyle(QFrame::NoFrame);
d->tipText->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); d->tipText->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
QPalette tipPal(d->tipText->palette()); QPalette tipPal(d->tipText->palette());
tipPal.setColor(QPalette::Base, Qt::transparent); tipPal.setColor(QPalette::Base, Qt::transparent);
tipPal.setColor(QPalette::Text, tipPal.color(QPalette::WindowText)); tipPal.setColor(QPalette::Text, tipPal.color(QPalette::WindowText));
d->tipText->setPalette(tipPal); d->tipText->setPalette(tipPal);
browserLayout->addWidget( d->tipText ); browserLayout->addWidget(d->tipText);
QLabel *label = new QLabel( this ); QLabel *label = new QLabel(this);
label->setPixmap( KStandardDirs::locate( "data", "kdeui/pics/ktip-bulb.png" ) ); label->setPixmap(KStandardDirs::locate("data", "kdeui/pics/ktip-bulb.png"));
label->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); label->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
browserLayout->addWidget( label ); browserLayout->addWidget(label);
if (!isTipDialog) {
resize(520, 280);
if ( !isTipDialog ) {
resize( 520, 280 );
QSize sh = size(); QSize sh = size();
QRect rect = KGlobalSettings::splashScreenDesktopGeometry(); QRect rect = KGlobalSettings::splashScreenDesktopGeometry();
move(
move( rect.x() + ( rect.width() - sh.width() ) / 2, rect.x() + (rect.width() - sh.width()) / 2,
rect.y() + ( rect.height() - sh.height() ) / 2 ); rect.y() + (rect.height() - sh.height()) / 2
);
} }
KSeparator* sep = new KSeparator( Qt::Horizontal ); KSeparator* sep = new KSeparator(Qt::Horizontal);
mainLayout->addWidget( sep ); mainLayout->addWidget(sep);
QHBoxLayout *buttonLayout = new QHBoxLayout(); QHBoxLayout *buttonLayout = new QHBoxLayout();
mainLayout->addLayout( buttonLayout ); mainLayout->addLayout(buttonLayout);
d->tipOnStart = new QCheckBox( i18n( "&Show tips on startup" ) ); d->tipOnStart = new QCheckBox(i18n("&Show tips on startup"));
buttonLayout->addWidget( d->tipOnStart, 1 ); buttonLayout->addWidget(d->tipOnStart, 1);
KPushButton *prev = new KPushButton( KStandardGuiItem::back( KStandardGuiItem::UseRTL ) ); KPushButton *prev = new KPushButton(KStandardGuiItem::back(KStandardGuiItem::UseRTL));
prev->setText( i18n( "&Previous" ) ); prev->setText(i18n("&Previous"));
buttonLayout->addWidget( prev ); buttonLayout->addWidget( prev );
KPushButton *next = new KPushButton( KStandardGuiItem::forward( KStandardGuiItem::UseRTL )); KPushButton *next = new KPushButton(KStandardGuiItem::forward(KStandardGuiItem::UseRTL));
next->setText( i18nc( "Opposite to Previous", "&Next" ) ); next->setText(i18nc("Opposite to Previous", "&Next"));
buttonLayout->addWidget( next ); buttonLayout->addWidget(next);
KPushButton *ok = new KPushButton( KStandardGuiItem::close()); KPushButton *ok = new KPushButton(KStandardGuiItem::close());
ok->setDefault( true ); ok->setDefault(true);
buttonLayout->addWidget( ok ); buttonLayout->addWidget(ok);
KConfigGroup config( KGlobal::config(), "TipOfDay" ); KConfigGroup config(KGlobal::config(), "TipOfDay");
d->tipOnStart->setChecked( config.readEntry( "RunOnStart", true ) ); d->tipOnStart->setChecked(config.readEntry("RunOnStart", true));
connect( next, SIGNAL(clicked()), this, SLOT(_k_nextTip()) ); connect(next, SIGNAL(clicked()), this, SLOT(_k_nextTip()));
connect( prev, SIGNAL(clicked()), this, SLOT(_k_prevTip()) ); connect(prev, SIGNAL(clicked()), this, SLOT(_k_prevTip()));
connect( ok, SIGNAL(clicked()), this, SLOT(accept()) ); connect(ok, SIGNAL(clicked()), this, SLOT(accept()));
connect( d->tipOnStart, SIGNAL(toggled(bool)), this, SLOT(_k_showOnStart(bool)) ); connect(d->tipOnStart, SIGNAL(toggled(bool)), this, SLOT(_k_showOnStart(bool)));
ok->setFocus(); ok->setFocus();
@ -328,8 +329,9 @@ KTipDialog::KTipDialog( KTipDatabase *database, QWidget *parent )
KTipDialog::~KTipDialog() KTipDialog::~KTipDialog()
{ {
if ( Private::mInstance == this ) if (Private::mInstance == this) {
Private::mInstance = 0L; Private::mInstance = nullptr;
}
delete d; delete d;
} }
@ -337,68 +339,76 @@ KTipDialog::~KTipDialog()
* use the one with a parent window as parameter instead of this one * use the one with a parent window as parameter instead of this one
* or you will get focus problems * or you will get focus problems
*/ */
void KTipDialog::showTip( const QString &tipFile, bool force ) void KTipDialog::showTip(const QString &tipFile, bool force)
{ {
showTip( 0, tipFile, force ); showTip(nullptr, tipFile, force);
} }
void KTipDialog::showTip( QWidget *parent, const QString &tipFile, bool force ) void KTipDialog::showTip(QWidget *parent, const QString &tipFile, bool force)
{ {
showMultiTip( parent, QStringList( tipFile ), force ); showMultiTip(parent, QStringList(tipFile), force);
} }
void KTipDialog::showMultiTip( QWidget *parent, const QStringList &tipFiles, bool force ) void KTipDialog::showMultiTip(QWidget *parent, const QStringList &tipFiles, bool force)
{ {
KConfigGroup configGroup( KGlobal::config(), "TipOfDay" ); KConfigGroup configGroup( KGlobal::config(), "TipOfDay");
const bool runOnStart = configGroup.readEntry( "RunOnStart", true ); const bool runOnStart = configGroup.readEntry("RunOnStart", true);
if ( !force ) { if (!force) {
if ( !runOnStart ) if (!runOnStart) {
return; return;
}
// showing the tooltips on startup suggests the tooltip // showing the tooltips on startup suggests the tooltip
// will be shown *each time* on startup, not $random days later // will be shown *each time* on startup, not $random days later
// TODO either remove or uncomment this code, but make the situation clear // TODO either remove or uncomment this code, but make the situation clear
/*bool hasLastShown = configGroup.hasKey( "TipLastShown" ); #if 0
if ( hasLastShown ) { bool hasLastShown = configGroup.hasKey("TipLastShown");
if (hasLastShown) {
const int oneDay = 24 * 60 * 60; const int oneDay = 24 * 60 * 60;
QDateTime lastShown = configGroup.readEntry( "TipLastShown", QDateTime() ); QDateTime lastShown = configGroup.readEntry("TipLastShown", QDateTime());
// Show tip roughly once a week // Show tip roughly once a week
if ( lastShown.secsTo( QDateTime::currentDateTime() ) < (oneDay + (KRandom::randomMax(10 * oneDay))) ) if (lastShown.secsTo(QDateTime::currentDateTime()) < (oneDay + (KRandom::randomMax(10 * oneDay)))) {
return; return;
} }
}
configGroup.writeEntry( "TipLastShown", QDateTime::currentDateTime() ); configGroup.writeEntry( "TipLastShown", QDateTime::currentDateTime() );
if ( !hasLastShown ) if (!hasLastShown) {
return; // Don't show tip on first start*/ return; // Don't show tip on first start
}
#endif
} }
if ( !Private::mInstance ) if (!Private::mInstance) {
Private::mInstance = new KTipDialog( new KTipDatabase( tipFiles ), parent ); Private::mInstance = new KTipDialog(new KTipDatabase(tipFiles), parent);
else } else {
// The application might have changed the RunOnStart option in its own // The application might have changed the RunOnStart option in its own
// configuration dialog, so we should update the checkbox. // configuration dialog, so we should update the checkbox.
Private::mInstance->d->tipOnStart->setChecked( runOnStart ); Private::mInstance->d->tipOnStart->setChecked(runOnStart);
}
Private::mInstance->show(); Private::mInstance->show();
Private::mInstance->raise(); Private::mInstance->raise();
} }
void KTipDialog::setShowOnStart( bool on ) void KTipDialog::setShowOnStart(bool on)
{ {
KConfigGroup config( KGlobal::config(), "TipOfDay" ); KConfigGroup config(KGlobal::config(), "TipOfDay");
config.writeEntry( "RunOnStart", on ); config.writeEntry("RunOnStart", on);
} }
bool KTipDialog::eventFilter( QObject *object, QEvent *event ) bool KTipDialog::eventFilter(QObject *object, QEvent *event)
{ {
if ( object == d->tipText && event->type() == QEvent::KeyPress && if (object == d->tipText && event->type() == QEvent::KeyPress &&
(((QKeyEvent *)event)->key() == Qt::Key_Return || (((QKeyEvent *)event)->key() == Qt::Key_Return ||
((QKeyEvent *)event)->key() == Qt::Key_Space )) ((QKeyEvent *)event)->key() == Qt::Key_Space))
{
accept(); accept();
}
/** /**
* If the user presses Return or Space, we close the dialog as if the * If the user presses Return or Space, we close the dialog as if the
@ -408,8 +418,7 @@ bool KTipDialog::eventFilter( QObject *object, QEvent *event )
* the key event _additionally_. (Antonio) * the key event _additionally_. (Antonio)
*/ */
return QWidget::eventFilter( object, event ); return QWidget::eventFilter(object, event);
} }
#include "moc_ktip.cpp" #include "moc_ktip.cpp"

View file

@ -52,14 +52,14 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
class KDEUI_EXPORT KTipDatabase class KDEUI_EXPORT KTipDatabase
{ {
public: public:
/** /**
* This constructor reads in the tips from a file with the given name. If * This constructor reads in the tips from a file with the given name. If
* no name is given, a file called 'application-name/tips' will be loaded. * no name is given, a file called 'application-name/tips' will be loaded.
* *
* @param tipFile The absolute path to the tips file. * @param tipFile The absolute path to the tips file.
*/ */
explicit KTipDatabase( const QString &tipFile = QString() ); explicit KTipDatabase(const QString &tipFile = QString());
/** /**
* This constructor takes a list of files that will be merged. This constructor * This constructor takes a list of files that will be merged. This constructor
@ -67,7 +67,7 @@ class KDEUI_EXPORT KTipDatabase
* *
* @param tipFiles A list of absolute paths to the tips file * @param tipFiles A list of absolute paths to the tips file
*/ */
explicit KTipDatabase( const QStringList &tipFiles ); explicit KTipDatabase(const QStringList &tipFiles);
~KTipDatabase(); ~KTipDatabase();
@ -86,11 +86,11 @@ class KDEUI_EXPORT KTipDatabase
*/ */
void prevTip(); void prevTip();
private: private:
class Private; class Private;
Private* const d; Private* const d;
Q_DISABLE_COPY( KTipDatabase ) Q_DISABLE_COPY(KTipDatabase)
}; };
/** /**
@ -103,8 +103,7 @@ class KDEUI_EXPORT KTipDatabase
class KDEUI_EXPORT KTipDialog : public KDialog class KDEUI_EXPORT KTipDialog : public KDialog
{ {
Q_OBJECT Q_OBJECT
public:
public:
/** /**
* Construct a tip dialog. * Construct a tip dialog.
* *
@ -112,7 +111,7 @@ class KDEUI_EXPORT KTipDialog : public KDialog
* will take ownership of the database, including deleting it. * will take ownership of the database, including deleting it.
* @param parent Parent widget of TipDialog. * @param parent Parent widget of TipDialog.
*/ */
explicit KTipDialog( KTipDatabase *database, QWidget *parent = 0 ); explicit KTipDialog(KTipDatabase *database, QWidget *parent = nullptr);
/** /**
* Destroys the tip dialog. * Destroys the tip dialog.
@ -135,7 +134,7 @@ class KDEUI_EXPORT KTipDialog : public KDialog
* @param force If true, the dialog is show, even when the users * @param force If true, the dialog is show, even when the users
* disabled it. * disabled it.
*/ */
static void showTip( QWidget *parent, const QString &tipFile = QString(), bool force = false ); static void showTip(QWidget *parent, const QString &tipFile = QString(), bool force = false);
/** /**
* Shows a tip * Shows a tip
@ -148,7 +147,7 @@ class KDEUI_EXPORT KTipDialog : public KDialog
* @param force If true, the dialog is show, even when the users * @param force If true, the dialog is show, even when the users
* disabled it. * disabled it.
*/ */
static void showMultiTip( QWidget *parent, const QStringList &tipFiles, bool force = false ); static void showMultiTip(QWidget *parent, const QStringList &tipFiles, bool force = false);
/** /**
* Shows a tip. * Shows a tip.
@ -156,7 +155,7 @@ class KDEUI_EXPORT KTipDialog : public KDialog
* This methods calls showTip() with the applications main window as parent. * This methods calls showTip() with the applications main window as parent.
* *
*/ */
static void showTip( const QString &tipFile = QString(), bool force = false ); static void showTip(const QString &tipFile = QString(), bool force = false);
/** /**
* Toggles the start behavior. * Toggles the start behavior.
@ -164,18 +163,18 @@ class KDEUI_EXPORT KTipDialog : public KDialog
* Normally, the user can disable the display of the tip in the dialog. * Normally, the user can disable the display of the tip in the dialog.
* This is just a way to change this setting from outside. * This is just a way to change this setting from outside.
*/ */
static void setShowOnStart( bool show ); static void setShowOnStart(bool show);
protected: protected:
bool eventFilter( QObject*, QEvent* ); bool eventFilter(QObject *object, QEvent *event);
private: private:
class Private; class Private;
Private* const d; Private* const d;
Q_PRIVATE_SLOT( d, void _k_nextTip() ) Q_PRIVATE_SLOT(d, void _k_nextTip())
Q_PRIVATE_SLOT( d, void _k_prevTip() ) Q_PRIVATE_SLOT(d, void _k_prevTip())
Q_PRIVATE_SLOT( d, void _k_showOnStart( bool ) ) Q_PRIVATE_SLOT(d, void _k_showOnStart(bool))
Q_DISABLE_COPY(KTipDialog) Q_DISABLE_COPY(KTipDialog)
}; };