mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-24 02:42:48 +00:00
kdeui: KDialog::setCaption() optimization
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
82bbcf9b77
commit
4e98703f75
2 changed files with 329 additions and 314 deletions
|
@ -63,8 +63,9 @@ void KDialogPrivate::setupLayout()
|
|||
|
||||
void KDialogPrivate::queuedLayoutUpdate()
|
||||
{
|
||||
if (!dirty)
|
||||
if (!dirty) {
|
||||
return;
|
||||
}
|
||||
|
||||
dirty = false;
|
||||
|
||||
|
@ -81,22 +82,27 @@ void KDialogPrivate::queuedLayoutUpdate()
|
|||
|
||||
delete mTopLayout;
|
||||
|
||||
if ( mButtonOrientation == Qt::Horizontal )
|
||||
if (mButtonOrientation == Qt::Horizontal) {
|
||||
mTopLayout = new QVBoxLayout(q);
|
||||
else
|
||||
} else {
|
||||
mTopLayout = new QHBoxLayout(q);
|
||||
}
|
||||
|
||||
if ( mUrlHelp )
|
||||
if (mUrlHelp) {
|
||||
mTopLayout->addWidget(mUrlHelp, 0, Qt::AlignRight);
|
||||
}
|
||||
|
||||
if ( mMainWidget )
|
||||
if (mMainWidget) {
|
||||
mTopLayout->addWidget(mMainWidget, 10);
|
||||
}
|
||||
|
||||
if ( mDetailsWidget )
|
||||
if (mDetailsWidget) {
|
||||
mTopLayout->addWidget(mDetailsWidget);
|
||||
}
|
||||
|
||||
if ( mActionSeparator )
|
||||
if (mActionSeparator) {
|
||||
mTopLayout->addWidget(mActionSeparator);
|
||||
}
|
||||
|
||||
if (mButtonBox) {
|
||||
mButtonBox->setOrientation(mButtonOrientation);
|
||||
|
@ -149,8 +155,9 @@ void KDialogPrivate::appendButton(KDialog::ButtonCode key, const KGuiItem &item)
|
|||
break;
|
||||
}
|
||||
|
||||
if ( role == QDialogButtonBox::InvalidRole )
|
||||
if (role == QDialogButtonBox::InvalidRole) {
|
||||
return;
|
||||
}
|
||||
|
||||
KPushButton *button = new KPushButton(item);
|
||||
mButtonBox->addButton(button, role);
|
||||
|
@ -158,8 +165,7 @@ void KDialogPrivate::appendButton(KDialog::ButtonCode key, const KGuiItem &item)
|
|||
mButtonList.insert(key, button);
|
||||
mButtonSignalMapper.setMapping(button, key);
|
||||
|
||||
QObject::connect(button, SIGNAL(clicked()),
|
||||
&mButtonSignalMapper, SLOT(map()) );
|
||||
QObject::connect(button, SIGNAL(clicked()), &mButtonSignalMapper, SLOT(map()));
|
||||
|
||||
if (key == mDefaultButton) {
|
||||
// Now that it exists, set it as default
|
||||
|
@ -187,13 +193,15 @@ void KDialogPrivate::helpLinkClicked()
|
|||
}
|
||||
|
||||
KDialog::KDialog(QWidget *parent, Qt::WindowFlags flags)
|
||||
: QDialog(parent, sAllowEmbeddingInGraphicsView ? flags : flags | Qt::BypassGraphicsProxyWidget ), d_ptr(new KDialogPrivate)
|
||||
: QDialog(parent, sAllowEmbeddingInGraphicsView ? flags : flags | Qt::BypassGraphicsProxyWidget ),
|
||||
d_ptr(new KDialogPrivate())
|
||||
{
|
||||
d_ptr->init(this);
|
||||
}
|
||||
|
||||
KDialog::KDialog(KDialogPrivate &dd, QWidget *parent, Qt::WindowFlags flags)
|
||||
: QDialog(parent, sAllowEmbeddingInGraphicsView ? flags : flags | Qt::BypassGraphicsProxyWidget), d_ptr(&dd)
|
||||
: QDialog(parent, sAllowEmbeddingInGraphicsView ? flags : flags | Qt::BypassGraphicsProxyWidget),
|
||||
d_ptr(&dd)
|
||||
{
|
||||
d_ptr->init(this);
|
||||
}
|
||||
|
@ -213,51 +221,64 @@ void KDialog::setButtons( ButtonCodes buttonMask )
|
|||
d->mButtonBox = 0;
|
||||
}
|
||||
|
||||
if ( buttonMask & Cancel )
|
||||
buttonMask &= ~Close;
|
||||
if (buttonMask & KDialog::Cancel)
|
||||
buttonMask &= ~KDialog::Close;
|
||||
|
||||
if ( buttonMask & Apply )
|
||||
buttonMask &= ~Try;
|
||||
if (buttonMask & KDialog::Apply)
|
||||
buttonMask &= ~KDialog::Try;
|
||||
|
||||
if ( buttonMask & Details )
|
||||
buttonMask &= ~Default;
|
||||
if (buttonMask & KDialog::Details)
|
||||
buttonMask &= ~KDialog::Default;
|
||||
|
||||
if ( buttonMask == None ) {
|
||||
if (buttonMask == KDialog::None) {
|
||||
d->setupLayout();
|
||||
return; // When we want no button box
|
||||
}
|
||||
|
||||
d->mEscapeButton = (buttonMask & Cancel) ? Cancel : Close;
|
||||
d->mEscapeButton = (buttonMask & KDialog::Cancel) ? KDialog::Cancel : KDialog::Close;
|
||||
d->mButtonBox = new QDialogButtonBox(this);
|
||||
|
||||
if ( buttonMask & Help )
|
||||
d->appendButton( Help, KStandardGuiItem::help() );
|
||||
if ( buttonMask & Default )
|
||||
d->appendButton( Default, KStandardGuiItem::defaults() );
|
||||
if ( buttonMask & Reset )
|
||||
d->appendButton( Reset, KStandardGuiItem::reset() );
|
||||
if ( buttonMask & User3 )
|
||||
d->appendButton( User3, KGuiItem() );
|
||||
if ( buttonMask & User2 )
|
||||
d->appendButton( User2, KGuiItem() );
|
||||
if ( buttonMask & User1 )
|
||||
d->appendButton( User1, KGuiItem() );
|
||||
if ( buttonMask & Ok )
|
||||
d->appendButton( Ok, KStandardGuiItem::ok() );
|
||||
if ( buttonMask & Apply )
|
||||
d->appendButton( Apply, KStandardGuiItem::apply() );
|
||||
if ( buttonMask & Try )
|
||||
d->appendButton( Try, KGuiItem(i18n( "&Try" )) );
|
||||
if ( buttonMask & Cancel )
|
||||
d->appendButton( Cancel, KStandardGuiItem::cancel() );
|
||||
if ( buttonMask & Close )
|
||||
d->appendButton( Close, KStandardGuiItem::close() );
|
||||
if ( buttonMask & Yes )
|
||||
d->appendButton( Yes, KStandardGuiItem::yes() );
|
||||
if ( buttonMask & No )
|
||||
d->appendButton( No, KStandardGuiItem::no() );
|
||||
if ( buttonMask & Details ) {
|
||||
d->appendButton( Details, KGuiItem(QString(), "help-about") );
|
||||
if (buttonMask & KDialog::Help) {
|
||||
d->appendButton(KDialog::Help, KStandardGuiItem::help());
|
||||
}
|
||||
if (buttonMask & KDialog::Default) {
|
||||
d->appendButton(KDialog::Default, KStandardGuiItem::defaults());
|
||||
}
|
||||
if (buttonMask & KDialog::Reset) {
|
||||
d->appendButton(KDialog::Reset, KStandardGuiItem::reset());
|
||||
}
|
||||
if (buttonMask & KDialog::User3) {
|
||||
d->appendButton(KDialog::User3, KGuiItem());
|
||||
}
|
||||
if (buttonMask & KDialog::User2) {
|
||||
d->appendButton(KDialog::User2, KGuiItem());
|
||||
}
|
||||
if (buttonMask & KDialog::User1) {
|
||||
d->appendButton(KDialog::User1, KGuiItem());
|
||||
}
|
||||
if (buttonMask & KDialog::Ok) {
|
||||
d->appendButton(KDialog::Ok, KStandardGuiItem::ok());
|
||||
}
|
||||
if (buttonMask & KDialog::Apply) {
|
||||
d->appendButton(KDialog::Apply, KStandardGuiItem::apply());
|
||||
}
|
||||
if (buttonMask & KDialog::Try) {
|
||||
d->appendButton(KDialog::Try, KGuiItem(i18n("&Try")));
|
||||
}
|
||||
if (buttonMask & KDialog::Cancel) {
|
||||
d->appendButton(KDialog::Cancel, KStandardGuiItem::cancel());
|
||||
}
|
||||
if (buttonMask & KDialog::Close) {
|
||||
d->appendButton(KDialog::Close, KStandardGuiItem::close());
|
||||
}
|
||||
if (buttonMask & KDialog::Yes) {
|
||||
d->appendButton(KDialog::Yes, KStandardGuiItem::yes());
|
||||
}
|
||||
if (buttonMask & KDialog::No) {
|
||||
d->appendButton(KDialog::No, KStandardGuiItem::no());
|
||||
}
|
||||
if (buttonMask & KDialog::Details) {
|
||||
d->appendButton(KDialog::Details, KGuiItem(QString(), "help-about"));
|
||||
setDetailsWidgetVisible(false);
|
||||
}
|
||||
|
||||
|
@ -271,13 +292,15 @@ void KDialog::setButtonsOrientation( Qt::Orientation orientation )
|
|||
if (d->mButtonOrientation != orientation) {
|
||||
d->mButtonOrientation = orientation;
|
||||
|
||||
if ( d->mActionSeparator )
|
||||
if (d->mActionSeparator) {
|
||||
d->mActionSeparator->setOrientation(d->mButtonOrientation);
|
||||
}
|
||||
|
||||
if ( d->mButtonOrientation == Qt::Vertical )
|
||||
if (d->mButtonOrientation == Qt::Vertical) {
|
||||
enableLinkedHelp(false); // 2000-06-18 Espen: No support for this yet.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void KDialog::setEscapeButton(ButtonCode id)
|
||||
{
|
||||
|
@ -288,14 +311,15 @@ void KDialog::setDefaultButton( ButtonCode newDefaultButton )
|
|||
{
|
||||
Q_D(KDialog);
|
||||
|
||||
if (newDefaultButton == None)
|
||||
newDefaultButton = NoDefault; // #148969
|
||||
if (newDefaultButton == KDialog::None) {
|
||||
newDefaultButton = KDialog::NoDefault; // #148969
|
||||
}
|
||||
|
||||
const KDialog::ButtonCode oldDefault = defaultButton();
|
||||
|
||||
bool oldDefaultHadFocus = false;
|
||||
|
||||
if (oldDefault != NoDefault) {
|
||||
if (oldDefault != KDialog::NoDefault) {
|
||||
KPushButton *old = button(oldDefault);
|
||||
if (old) {
|
||||
oldDefaultHadFocus = (focusWidget() == old);
|
||||
|
@ -303,7 +327,7 @@ void KDialog::setDefaultButton( ButtonCode newDefaultButton )
|
|||
}
|
||||
}
|
||||
|
||||
if (newDefaultButton != NoDefault) {
|
||||
if (newDefaultButton != KDialog::NoDefault) {
|
||||
KPushButton *b = button(newDefaultButton);
|
||||
if (b) {
|
||||
b->setDefault(true);
|
||||
|
@ -328,7 +352,7 @@ KDialog::ButtonCode KDialog::defaultButton() const
|
|||
while (it.hasNext()) {
|
||||
it.next();
|
||||
if (it.value()->isDefault()) {
|
||||
return (ButtonCode)it.key();
|
||||
return static_cast<KDialog::ButtonCode>(it.key());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -338,8 +362,9 @@ KDialog::ButtonCode KDialog::defaultButton() const
|
|||
void KDialog::setMainWidget(QWidget *widget)
|
||||
{
|
||||
Q_D(KDialog);
|
||||
if ( d->mMainWidget == widget )
|
||||
if (d->mMainWidget == widget) {
|
||||
return;
|
||||
}
|
||||
d->mMainWidget = widget;
|
||||
if (d->mMainWidget && d->mMainWidget->layout()) {
|
||||
// Avoid double-margin problem
|
||||
|
@ -351,30 +376,30 @@ void KDialog::setMainWidget( QWidget *widget )
|
|||
QWidget *KDialog::mainWidget()
|
||||
{
|
||||
Q_D(KDialog);
|
||||
if (!d->mMainWidget)
|
||||
if (!d->mMainWidget) {
|
||||
setMainWidget(new QWidget(this));
|
||||
}
|
||||
return d->mMainWidget;
|
||||
}
|
||||
|
||||
QSize KDialog::sizeHint() const
|
||||
{
|
||||
Q_D(const KDialog);
|
||||
|
||||
if (!d->mMinSize.isEmpty())
|
||||
if (!d->mMinSize.isEmpty()) {
|
||||
return d->mMinSize.expandedTo( minimumSizeHint() ) + d->mIncSize;
|
||||
else {
|
||||
if (d->dirty)
|
||||
const_cast<KDialogPrivate*>(d)->queuedLayoutUpdate();
|
||||
return QDialog::sizeHint() + d->mIncSize;
|
||||
}
|
||||
if (d->dirty) {
|
||||
const_cast<KDialogPrivate*>(d)->queuedLayoutUpdate();
|
||||
}
|
||||
return QDialog::sizeHint() + d->mIncSize;
|
||||
}
|
||||
|
||||
QSize KDialog::minimumSizeHint() const
|
||||
{
|
||||
Q_D(const KDialog);
|
||||
|
||||
if (d->dirty)
|
||||
if (d->dirty) {
|
||||
const_cast<KDialogPrivate*>(d)->queuedLayoutUpdate();
|
||||
}
|
||||
return QDialog::minimumSizeHint() + d->mIncSize;
|
||||
}
|
||||
|
||||
|
@ -386,8 +411,7 @@ void KDialog::keyPressEvent( QKeyEvent *event )
|
|||
Q_D(KDialog);
|
||||
if (event->modifiers() == 0) {
|
||||
if (event->key() == Qt::Key_F1) {
|
||||
KPushButton *button = this->button( Help );
|
||||
|
||||
KPushButton *button = this->button(KDialog::Help);
|
||||
if (button) {
|
||||
button->animateClick();
|
||||
event->accept();
|
||||
|
@ -397,23 +421,21 @@ void KDialog::keyPressEvent( QKeyEvent *event )
|
|||
|
||||
if (event->key() == Qt::Key_Escape) {
|
||||
KPushButton *button = this->button(d->mEscapeButton);
|
||||
|
||||
if (button) {
|
||||
button->animateClick();
|
||||
event->accept();
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
} else if (event->key() == Qt::Key_F1 && event->modifiers() == Qt::ShiftModifier) {
|
||||
QWhatsThis::enterWhatsThisMode();
|
||||
event->accept();
|
||||
return;
|
||||
} else if (event->modifiers() == Qt::ControlModifier &&
|
||||
( event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter ) ) {
|
||||
(event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter))
|
||||
{
|
||||
// accept the dialog when Ctrl-Return is pressed
|
||||
KPushButton *button = this->button( Ok );
|
||||
|
||||
KPushButton *button = this->button(KDialog::Ok);
|
||||
if (button) {
|
||||
button->animateClick();
|
||||
event->accept();
|
||||
|
@ -448,15 +470,14 @@ QString KDialog::makeStandardCaption( const QString &userCaption,
|
|||
QString captionString = userCaption.isEmpty() ? caption : userCaption;
|
||||
|
||||
// If the document is modified, add '[modified]'.
|
||||
if (flags & ModifiedCaption)
|
||||
if (flags & KDialog::ModifiedCaption) {
|
||||
captionString += QString::fromUtf8(" [") + i18n("modified") + QString::fromUtf8("]");
|
||||
}
|
||||
|
||||
if (!userCaption.isEmpty()) {
|
||||
// Add the application name if:
|
||||
// User asked for it, it's not a duplication and the app name (caption()) is not empty
|
||||
if ( flags & AppNameCaption &&
|
||||
!caption.isEmpty() &&
|
||||
!userCaption.endsWith(caption) ) {
|
||||
if ( flags & AppNameCaption && !caption.isEmpty() && !userCaption.endsWith(caption)) {
|
||||
// TODO: check to see if this is a transient/secondary window before trying to add the app name
|
||||
// on platforms that need this
|
||||
captionString += i18nc("Document/application separator in titlebar", " – ") + caption;
|
||||
|
@ -466,21 +487,17 @@ QString KDialog::makeStandardCaption( const QString &userCaption,
|
|||
return captionString;
|
||||
}
|
||||
|
||||
void KDialog::setCaption( const QString &_caption )
|
||||
void KDialog::setCaption(const QString &caption)
|
||||
{
|
||||
const QString caption = makeStandardCaption( _caption, this );
|
||||
setWindowTitle( caption );
|
||||
setWindowTitle(makeStandardCaption(caption, this));
|
||||
}
|
||||
|
||||
void KDialog::setCaption(const QString &caption, bool modified)
|
||||
{
|
||||
CaptionFlags flags = HIGCompliantCaption;
|
||||
|
||||
if ( modified )
|
||||
{
|
||||
if (modified) {
|
||||
flags |= ModifiedCaption;
|
||||
}
|
||||
|
||||
setWindowTitle(makeStandardCaption(caption, this, flags));
|
||||
}
|
||||
|
||||
|
|
|
@ -130,9 +130,7 @@ class KDEUI_EXPORT KDialog : public QDialog
|
|||
Q_OBJECT
|
||||
Q_ENUMS(ButtonCode)
|
||||
Q_DECLARE_PRIVATE(KDialog)
|
||||
|
||||
public:
|
||||
|
||||
enum ButtonCode
|
||||
{
|
||||
None = 0x00000000,
|
||||
|
@ -169,7 +167,7 @@ class KDEUI_EXPORT KDialog : public QDialog
|
|||
* @param parent The parent of the dialog.
|
||||
* @param flags The widget flags passed to the QDialog constructor
|
||||
*/
|
||||
explicit KDialog( QWidget *parent = 0, Qt::WindowFlags flags = 0 );
|
||||
explicit KDialog(QWidget *parent = nullptr, Qt::WindowFlags flags = 0);
|
||||
|
||||
/**
|
||||
* Destroys the dialog.
|
||||
|
@ -467,7 +465,7 @@ class KDEUI_EXPORT KDialog : public QDialog
|
|||
* @return the created caption
|
||||
*/
|
||||
static QString makeStandardCaption(const QString &userCaption,
|
||||
QWidget* window = 0,
|
||||
QWidget* window = nullptr,
|
||||
CaptionFlags flags = HIGCompliantCaption);
|
||||
|
||||
/**
|
||||
|
@ -760,7 +758,7 @@ class KDEUI_EXPORT KDialog : public QDialog
|
|||
* Emits the #hidden signal. You can connect to that signal to
|
||||
* detect when a dialog has been closed.
|
||||
*/
|
||||
virtual void hideEvent( QHideEvent * );
|
||||
virtual void hideEvent(QHideEvent *event);
|
||||
|
||||
/**
|
||||
* Detects when a dialog is being closed from the window manager
|
||||
|
@ -768,12 +766,12 @@ class KDEUI_EXPORT KDialog : public QDialog
|
|||
* is activated. Otherwise standard QDialog behavior
|
||||
* will take place.
|
||||
*/
|
||||
virtual void closeEvent( QCloseEvent *e );
|
||||
virtual void closeEvent( QCloseEvent *event);
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
virtual void keyPressEvent( QKeyEvent* );
|
||||
virtual void keyPressEvent(QKeyEvent *event);
|
||||
|
||||
protected Q_SLOTS:
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue