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;
};
KTipDialog *KTipDialog::Private::mInstance = 0;
KTipDialog *KTipDialog::Private::mInstance = nullptr;
void KTipDialog::Private::_k_prevTip()
{
@ -216,200 +216,209 @@ void KTipDialog::Private::_k_nextTip()
.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 )
: KDialog( parent ),
d( new Private( this ) )
KTipDialog::KTipDialog(KTipDatabase *database, QWidget *parent)
: KDialog(parent),
d(new Private(this))
{
setButtons( KDialog::None );
setCaption( i18n( "Tip of the Day" ) );
setButtons(KDialog::None);
setCaption(i18n("Tip of the Day"));
/**
* 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.
*/
bool isTipDialog = (parent != 0);
/**
* 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.
*/
bool isTipDialog = (parent != nullptr);
d->database = database;
d->database = database;
setWindowIcon(KIcon("ktip"));
setWindowIcon(KIcon("ktip"));
QWidget *widget = new QWidget( this );
setMainWidget( widget );
QVBoxLayout *mainLayout = new QVBoxLayout( widget );
mainLayout->setMargin( 0 );
QWidget *widget = new QWidget(this);
setMainWidget(widget);
QVBoxLayout *mainLayout = new QVBoxLayout(widget);
mainLayout->setMargin(0);
if ( isTipDialog ) {
QLabel *titleLabel = new QLabel( this );
titleLabel->setText( i18n( "Did you know...?\n" ) );
titleLabel->setFont( QFont( KGlobalSettings::generalFont().family(), 20, QFont::Bold ) );
titleLabel->setAlignment( Qt::AlignCenter );
mainLayout->addWidget( titleLabel );
}
if (isTipDialog) {
QLabel *titleLabel = new QLabel(this);
titleLabel->setText(i18n("Did you know...?\n" ) );
titleLabel->setFont(QFont(KGlobalSettings::generalFont().family(), 20, QFont::Bold));
titleLabel->setAlignment(Qt::AlignCenter);
mainLayout->addWidget(titleLabel);
}
QHBoxLayout *browserLayout = new QHBoxLayout();
mainLayout->addLayout( browserLayout );
QHBoxLayout *browserLayout = new QHBoxLayout();
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;
paths << KGlobal::dirs()->resourceDirs( "icon" )
<< KGlobal::dirs()->findResourceDir( "data", "kdewizard/pics" ) + "kdewizard/pics/";
QStringList paths;
paths << KGlobal::dirs()->resourceDirs("icon")
<< KGlobal::dirs()->findResourceDir("data", "kdewizard/pics") + "kdewizard/pics/";
d->tipText->setSearchPaths( paths );
d->tipText->setSearchPaths(paths);
d->tipText->setFrameStyle( QFrame::NoFrame );
d->tipText->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
QPalette tipPal(d->tipText->palette());
tipPal.setColor(QPalette::Base, Qt::transparent);
tipPal.setColor(QPalette::Text, tipPal.color(QPalette::WindowText));
d->tipText->setPalette(tipPal);
d->tipText->setFrameStyle(QFrame::NoFrame);
d->tipText->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
QPalette tipPal(d->tipText->palette());
tipPal.setColor(QPalette::Base, Qt::transparent);
tipPal.setColor(QPalette::Text, tipPal.color(QPalette::WindowText));
d->tipText->setPalette(tipPal);
browserLayout->addWidget( d->tipText );
browserLayout->addWidget(d->tipText);
QLabel *label = new QLabel( this );
label->setPixmap( KStandardDirs::locate( "data", "kdeui/pics/ktip-bulb.png" ) );
label->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
browserLayout->addWidget( label );
QLabel *label = new QLabel(this);
label->setPixmap(KStandardDirs::locate("data", "kdeui/pics/ktip-bulb.png"));
label->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
browserLayout->addWidget(label);
if ( !isTipDialog ) {
resize( 520, 280 );
QSize sh = size();
if (!isTipDialog) {
resize(520, 280);
QRect rect = KGlobalSettings::splashScreenDesktopGeometry();
QSize sh = size();
QRect rect = KGlobalSettings::splashScreenDesktopGeometry();
move(
rect.x() + (rect.width() - sh.width()) / 2,
rect.y() + (rect.height() - sh.height()) / 2
);
}
move( rect.x() + ( rect.width() - sh.width() ) / 2,
rect.y() + ( rect.height() - sh.height() ) / 2 );
}
KSeparator* sep = new KSeparator(Qt::Horizontal);
mainLayout->addWidget(sep);
KSeparator* sep = new KSeparator( Qt::Horizontal );
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"));
buttonLayout->addWidget(d->tipOnStart, 1);
d->tipOnStart = new QCheckBox( i18n( "&Show tips on startup" ) );
buttonLayout->addWidget( d->tipOnStart, 1 );
KPushButton *prev = new KPushButton(KStandardGuiItem::back(KStandardGuiItem::UseRTL));
prev->setText(i18n("&Previous"));
buttonLayout->addWidget( prev );
KPushButton *prev = new KPushButton( KStandardGuiItem::back( KStandardGuiItem::UseRTL ) );
prev->setText( i18n( "&Previous" ) );
buttonLayout->addWidget( prev );
KPushButton *next = new KPushButton(KStandardGuiItem::forward(KStandardGuiItem::UseRTL));
next->setText(i18nc("Opposite to Previous", "&Next"));
buttonLayout->addWidget(next);
KPushButton *next = new KPushButton( KStandardGuiItem::forward( KStandardGuiItem::UseRTL ));
next->setText( i18nc( "Opposite to Previous", "&Next" ) );
buttonLayout->addWidget( next );
KPushButton *ok = new KPushButton(KStandardGuiItem::close());
ok->setDefault(true);
buttonLayout->addWidget(ok);
KPushButton *ok = new KPushButton( KStandardGuiItem::close());
ok->setDefault( true );
buttonLayout->addWidget( ok );
KConfigGroup config(KGlobal::config(), "TipOfDay");
d->tipOnStart->setChecked(config.readEntry("RunOnStart", true));
KConfigGroup config( KGlobal::config(), "TipOfDay" );
d->tipOnStart->setChecked( config.readEntry( "RunOnStart", true ) );
connect(next, SIGNAL(clicked()), this, SLOT(_k_nextTip()));
connect(prev, SIGNAL(clicked()), this, SLOT(_k_prevTip()));
connect(ok, SIGNAL(clicked()), this, SLOT(accept()));
connect(d->tipOnStart, SIGNAL(toggled(bool)), this, SLOT(_k_showOnStart(bool)));
connect( next, SIGNAL(clicked()), this, SLOT(_k_nextTip()) );
connect( prev, SIGNAL(clicked()), this, SLOT(_k_prevTip()) );
connect( ok, SIGNAL(clicked()), this, SLOT(accept()) );
connect( d->tipOnStart, SIGNAL(toggled(bool)), this, SLOT(_k_showOnStart(bool)) );
ok->setFocus();
ok->setFocus();
d->_k_nextTip();
d->_k_nextTip();
}
KTipDialog::~KTipDialog()
{
if ( Private::mInstance == this )
Private::mInstance = 0L;
delete d;
if (Private::mInstance == this) {
Private::mInstance = nullptr;
}
delete d;
}
/**
* use the one with a parent window as parameter instead of this one
* 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 ( !runOnStart )
return;
if (!force) {
if (!runOnStart) {
return;
}
// showing the tooltips on startup suggests the tooltip
// will be shown *each time* on startup, not $random days later
// TODO either remove or uncomment this code, but make the situation clear
/*bool hasLastShown = configGroup.hasKey( "TipLastShown" );
if ( hasLastShown ) {
const int oneDay = 24 * 60 * 60;
QDateTime lastShown = configGroup.readEntry( "TipLastShown", QDateTime() );
// showing the tooltips on startup suggests the tooltip
// will be shown *each time* on startup, not $random days later
// TODO either remove or uncomment this code, but make the situation clear
#if 0
bool hasLastShown = configGroup.hasKey("TipLastShown");
if (hasLastShown) {
const int oneDay = 24 * 60 * 60;
QDateTime lastShown = configGroup.readEntry("TipLastShown", QDateTime());
// Show tip roughly once a week
if ( lastShown.secsTo( QDateTime::currentDateTime() ) < (oneDay + (KRandom::randomMax(10 * oneDay))) )
return;
// Show tip roughly once a week
if (lastShown.secsTo(QDateTime::currentDateTime()) < (oneDay + (KRandom::randomMax(10 * oneDay)))) {
return;
}
}
configGroup.writeEntry( "TipLastShown", QDateTime::currentDateTime() );
if (!hasLastShown) {
return; // Don't show tip on first start
}
#endif
}
configGroup.writeEntry( "TipLastShown", QDateTime::currentDateTime() );
if (!Private::mInstance) {
Private::mInstance = new KTipDialog(new KTipDatabase(tipFiles), parent);
} else {
// The application might have changed the RunOnStart option in its own
// configuration dialog, so we should update the checkbox.
Private::mInstance->d->tipOnStart->setChecked(runOnStart);
}
if ( !hasLastShown )
return; // Don't show tip on first start*/
}
if ( !Private::mInstance )
Private::mInstance = new KTipDialog( new KTipDatabase( tipFiles ), parent );
else
// The application might have changed the RunOnStart option in its own
// configuration dialog, so we should update the checkbox.
Private::mInstance->d->tipOnStart->setChecked( runOnStart );
Private::mInstance->show();
Private::mInstance->raise();
Private::mInstance->show();
Private::mInstance->raise();
}
void KTipDialog::setShowOnStart( bool on )
void KTipDialog::setShowOnStart(bool on)
{
KConfigGroup config( KGlobal::config(), "TipOfDay" );
config.writeEntry( "RunOnStart", on );
KConfigGroup config(KGlobal::config(), "TipOfDay");
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 &&
(((QKeyEvent *)event)->key() == Qt::Key_Return ||
((QKeyEvent *)event)->key() == Qt::Key_Space ))
accept();
if (object == d->tipText && event->type() == QEvent::KeyPress &&
(((QKeyEvent *)event)->key() == Qt::Key_Return ||
((QKeyEvent *)event)->key() == Qt::Key_Space))
{
accept();
}
/**
* If the user presses Return or Space, we close the dialog as if the
* default button was pressed even if the QTextBrowser has the keyboard
* focus. This could have the bad side-effect that the user cannot use the
* keyboard to open urls in the QTextBrowser, so we just let it handle
* the key event _additionally_. (Antonio)
*/
/**
* If the user presses Return or Space, we close the dialog as if the
* default button was pressed even if the QTextBrowser has the keyboard
* focus. This could have the bad side-effect that the user cannot use the
* keyboard to open urls in the QTextBrowser, so we just let it handle
* the key event _additionally_. (Antonio)
*/
return QWidget::eventFilter( object, event );
return QWidget::eventFilter(object, event);
}
#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
{
public:
public:
/**
* 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.
*
* @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
@ -67,7 +67,7 @@ class KDEUI_EXPORT KTipDatabase
*
* @param tipFiles A list of absolute paths to the tips file
*/
explicit KTipDatabase( const QStringList &tipFiles );
explicit KTipDatabase(const QStringList &tipFiles);
~KTipDatabase();
@ -86,11 +86,11 @@ class KDEUI_EXPORT KTipDatabase
*/
void prevTip();
private:
private:
class Private;
Private* const d;
Q_DISABLE_COPY( KTipDatabase )
Q_DISABLE_COPY(KTipDatabase)
};
/**
@ -102,9 +102,8 @@ class KDEUI_EXPORT KTipDatabase
*/
class KDEUI_EXPORT KTipDialog : public KDialog
{
Q_OBJECT
public:
Q_OBJECT
public:
/**
* Construct a tip dialog.
*
@ -112,7 +111,7 @@ class KDEUI_EXPORT KTipDialog : public KDialog
* will take ownership of the database, including deleting it.
* @param parent Parent widget of TipDialog.
*/
explicit KTipDialog( KTipDatabase *database, QWidget *parent = 0 );
explicit KTipDialog(KTipDatabase *database, QWidget *parent = nullptr);
/**
* 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
* 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
@ -148,7 +147,7 @@ class KDEUI_EXPORT KTipDialog : public KDialog
* @param force If true, the dialog is show, even when the users
* 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.
@ -156,7 +155,7 @@ class KDEUI_EXPORT KTipDialog : public KDialog
* 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.
@ -164,18 +163,18 @@ class KDEUI_EXPORT KTipDialog : public KDialog
* Normally, the user can disable the display of the tip in the dialog.
* This is just a way to change this setting from outside.
*/
static void setShowOnStart( bool show );
static void setShowOnStart(bool show);
protected:
bool eventFilter( QObject*, QEvent* );
protected:
bool eventFilter(QObject *object, QEvent *event);
private:
private:
class Private;
Private* const d;
Q_PRIVATE_SLOT( d, void _k_nextTip() )
Q_PRIVATE_SLOT( d, void _k_prevTip() )
Q_PRIVATE_SLOT( d, void _k_showOnStart( bool ) )
Q_PRIVATE_SLOT(d, void _k_nextTip())
Q_PRIVATE_SLOT(d, void _k_prevTip())
Q_PRIVATE_SLOT(d, void _k_showOnStart(bool))
Q_DISABLE_COPY(KTipDialog)
};