Commit 3bb17ef4 authored by Laurent Montel's avatar Laurent Montel 😁 Committed by Pali Rohár

Fix dialog layout.

parent 2fbf7755
......@@ -40,86 +40,76 @@ namespace UI
class AvatarDialog::Private
{
public:
Private()
: mainWidget(0)
{}
Private()
: mainWidget(0)
{}
AvatarSelectorWidget *mainWidget;
QString selectedPath;
QString currentPath;
AvatarSelectorWidget *mainWidget;
QString selectedPath;
QString currentPath;
};
AvatarDialog::AvatarDialog(QWidget *parent)
: QDialog(parent), d(new Private)
: QDialog(parent), d(new Private)
{
setWindowTitle( i18n("Select Avatar") );
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel);
QWidget *mainWidget = new QWidget(this);
QVBoxLayout *mainLayout = new QVBoxLayout;
setLayout(mainLayout);
mainLayout->addWidget(mainWidget);
QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
okButton->setDefault(true);
okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
//PORTING SCRIPT: WARNING mainLayout->addWidget(buttonBox) must be last item in layout. Please move it.
mainLayout->addWidget(buttonBox);
d->mainWidget = new Kopete::UI::AvatarSelectorWidget(this);
//setMainWidget(d->mainWidget);
setWindowTitle( i18n("Select Avatar") );
QVBoxLayout *mainLayout = new QVBoxLayout(this);
d->mainWidget = new Kopete::UI::AvatarSelectorWidget(this);
mainLayout->addWidget(d->mainWidget);
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel, this);
QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
okButton->setDefault(true);
okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
connect(buttonBox, &QDialogButtonBox::accepted, this, &AvatarDialog::slotOkClicked);
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
mainLayout->addWidget(buttonBox);
}
AvatarDialog::~AvatarDialog()
{
delete d;
delete d;
}
QString AvatarDialog::selectedAvatarPath() const
{
return d->selectedPath;
return d->selectedPath;
}
QString AvatarDialog::getAvatar(QWidget *parent, const QString &currentAvatar, bool * ok )
{
QPointer <AvatarDialog> dialog = new AvatarDialog(parent);
dialog->d->mainWidget->setCurrentAvatar(currentAvatar);
dialog->d->currentPath = currentAvatar;
if ( dialog->exec() == QDialog::Accepted )
{
if ( ok ) {
*ok = true;
}
}
else
{
if ( ok ) {
*ok = false;
}
}
QString ret;
if ( dialog )
ret = dialog->selectedAvatarPath();
delete dialog;
return ret;
QPointer <AvatarDialog> dialog = new AvatarDialog(parent);
dialog->d->mainWidget->setCurrentAvatar(currentAvatar);
dialog->d->currentPath = currentAvatar;
if ( dialog->exec() == QDialog::Accepted )
{
if ( ok ) {
*ok = true;
}
}
else
{
if ( ok ) {
*ok = false;
}
}
QString ret;
if ( dialog )
ret = dialog->selectedAvatarPath();
delete dialog;
return ret;
}
//Adapt code and connect okbutton or other to new slot. It doesn't exist in qdialog
void AvatarDialog::slotButtonClicked(int button)
void AvatarDialog::slotOkClicked()
{
if (button == QDialogButtonBox::Ok)
{
Kopete::AvatarManager::AvatarEntry selectedEntry = d->mainWidget->selectedEntry();
Kopete::AvatarManager::AvatarEntry selectedEntry = d->mainWidget->selectedEntry();
d->selectedPath = selectedEntry.path;
emit result();
}
/* FIXME :Adapt code and connect okbutton or other to new slot. It doesn't exist in qdialog
QDialog::slotButtonClicked(button);
connect( button, SIGNAL(clicked()), SLOT(slotButtonClicked(int)) ); */
d->selectedPath = selectedEntry.path;
emit result();
accept();
}
} // namespace UI
} // namespace Kopete
......@@ -33,10 +33,10 @@ namespace UI
/**
* @brief Dialog to manage and select user avatar
*
* Using AvatarDialog is very simple, if you only want to retrieve an avatar, use
* Using AvatarDialog is very simple, if you only want to retrieve an avatar, use
* the @ref AvatarDialog::getAvatar() static method.
*
* If you want the operation to be asynchronous, you can use it like the following
* If you want the operation to be asynchronous, you can use it like the following
* example:
* @code
Kopete::UI::AvatarDialog *avatarDialog = new Kopete::UI::AvatarDialog(parent);
......@@ -48,8 +48,8 @@ avatarDialog->show();
* @code
void SpamEgg::avatarDialogResult(Kopete::UI::AvatarDialog *dialog)
{
// Set avatar to Myself metacontact
Kopete::ContactList::self()->myself()->setPhoto( KUrl(dialog->selectedAvatarPath()) );
// Set avatar to Myself metacontact
Kopete::ContactList::self()->myself()->setPhoto( KUrl(dialog->selectedAvatarPath()) );
}
* @endcode
*
......@@ -57,56 +57,52 @@ void SpamEgg::avatarDialogResult(Kopete::UI::AvatarDialog *dialog)
*/
class KOPETE_EXPORT AvatarDialog : public QDialog
{
Q_OBJECT
Q_OBJECT
public:
/**
* Create a new AvatarDialog
* @param parent Parent widget
*/
AvatarDialog(QWidget *parent = nullptr);
/**
* Clean-up resource of AvatarDialog
*/
virtual ~AvatarDialog();
/**
* @brief Get the selected avatar in dialog
*
* This method return the path of the selected avatar in
* dialog. Call this method in the resulting slot of
* signal result().
* @return the absolute path to the avatar
*/
QString selectedAvatarPath() const;
/**
* @brief Gets an avatar from the AvatarManager
*
* This method will open the avatar dialog for the user to choose
* an avatar.
* @param parent Parent widget
* @return The path of the selected avatar, or QString() if no avatar
* was chosen or if the Cancel button was pressed.
*/
static QString getAvatar(QWidget *parent = nullptr, const QString &currentAvatar = QString(), bool * ok = 0 );
/**
* Create a new AvatarDialog
* @param parent Parent widget
*/
AvatarDialog(QWidget *parent = nullptr);
/**
* Clean-up resource of AvatarDialog
*/
virtual ~AvatarDialog();
/**
* @brief Get the selected avatar in dialog
*
* This method return the path of the selected avatar in
* dialog. Call this method in the resulting slot of
* signal result().
* @return the absolute path to the avatar
*/
QString selectedAvatarPath() const;
/**
* @brief Gets an avatar from the AvatarManager
*
* This method will open the avatar dialog for the user to choose
* an avatar.
* @param parent Parent widget
* @return The path of the selected avatar, or QString() if no avatar
* was chosen or if the Cancel button was pressed.
*/
static QString getAvatar(QWidget *parent = nullptr, const QString &currentAvatar = QString(), bool * ok = 0 );
Q_SIGNALS:
/**
* This signal is emitted when Ok has been clicked
* before the dialog is closed
*/
void result();
protected Q_SLOTS:
/**
* @internal
* A button has been clicked. Reimplemented from @ref QDialog::slotButtonClicked()
*/
virtual void slotButtonClicked(int button);
/**
* This signal is emitted when Ok has been clicked
* before the dialog is closed
*/
void result();
private Q_SLOTS:
void slotOkClicked();
private:
class Private;
Private * const d;
class Private;
Private * const d;
};
} // namespace UI
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment