diff --git a/src/kassistantdialog.h b/src/kassistantdialog.h index ab42b96..b116657 100644 --- a/src/kassistantdialog.h +++ b/src/kassistantdialog.h @@ -1,156 +1,156 @@ /* This file is part of the KDE libraries Copyright (C) 2006 Olivier Goffart This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KASSISTANTDIALOG_H #define KASSISTANTDIALOG_H #include #include /** * @class KAssistantDialog kassistantdialog.h KAssistantDialog * * This class provides a framework for assistant dialogs. * * An assistant dialog consists of a sequence of pages. * Its purpose is to guide the user (assist) through a process step by step. * Assistant dialogs are useful for complex or infrequently occurring tasks * that people may find difficult to learn or do. * Sometimes a task requires too many input fields to fit them on a single dialog. * * Create and populate dialog pages that inherit from QWidget and add them * to the assistant dialog using addPage(). * * The functions next() and back() are virtual and may be reimplemented to * override the default actions of the next and back buttons. * * \image html kassistantdialog.png "KAssistantDialog" * * @author Olivier Goffart */ class KWIDGETSADDONS_EXPORT KAssistantDialog : public KPageDialog { Q_OBJECT public: /** * Construct a new assistant dialog with @p parent as parent. * @param parent is the parent of the widget. * @flags the window flags to give to the assistant dialog. The * default of zero is usually what you want. */ - explicit KAssistantDialog(QWidget *parent = nullptr, Qt::WindowFlags flags = nullptr); + explicit KAssistantDialog(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags()); virtual ~KAssistantDialog(); /** * Specify if the content of the page is valid, and if the next button may be enabled on this page. * By default all pages are valid. * * This will disable or enable the next button on the specified page * * @param page the page on which the next button will be enabled/disable * @param enable if true the next button will be enabled, if false it will be disabled */ void setValid(KPageWidgetItem *page, bool enable); /** * return if a page is valid * @param page the page to check the validity of * @see setValid() */ bool isValid(KPageWidgetItem *page) const; /** * Specify whether a page is appropriate. * * A page is considered inappropriate if it should not be shown due to * the contents of other pages making it inappropriate. * * A page which is inappropriate will not be shown. * * The last page in an assistant dialog should always be appropriate * @param page the page to set as appropriate * @param appropriate flag indicating the appropriateness of the page. * If @p appropriate is true, then @p page is appropriate and will be * shown in the assistant dialog. If false, @p page will not be shown. */ void setAppropriate(KPageWidgetItem *page, bool appropriate); /** * Check if a page is appropriate for use in the assistant dialog. * @param page is the page to check the appropriateness of. * @return true if @p page is appropriate, false if it is not */ bool isAppropriate(KPageWidgetItem *page) const; /** * @returns the next button */ QPushButton* nextButton() const; /** * @returns the finish button */ QPushButton* backButton() const; /** * @returns the finish button */ QPushButton* finishButton() const; public Q_SLOTS: /** * Called when the user clicks the Back button. * * This function will show the preceding relevant page in the sequence. * Do nothing if the current page is the first page in the sequence. */ virtual void back(); /** * Called when the user clicks the Next/Finish button. * * This function will show the next relevant page in the sequence. * If the current page is the last page, it will call accept() */ virtual void next(); protected: /** * Construct an assistant dialog from a single widget. * @param widget the widget to construct the dialog with * @param parent the parent of the assistant dialog * @flags the window flags to use when creating the widget. The default * of zero is usually fine. * * Calls the KPageDialog(KPageWidget *widget, QWidget *parent, Qt::WindowFlags flags) constructor */ - explicit KAssistantDialog(KPageWidget *widget, QWidget *parent = nullptr, Qt::WindowFlags flags = nullptr); + explicit KAssistantDialog(KPageWidget *widget, QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags()); void showEvent(QShowEvent *event) Q_DECL_OVERRIDE; private: class Private; Private *const d; Q_PRIVATE_SLOT(d, void _k_slotUpdateButtons()) Q_DISABLE_COPY(KAssistantDialog) }; #endif diff --git a/src/keditlistwidget.cpp b/src/keditlistwidget.cpp index d295c08..d727405 100644 --- a/src/keditlistwidget.cpp +++ b/src/keditlistwidget.cpp @@ -1,673 +1,673 @@ /* This file is part of the KDE libraries Copyright (C) 2000 David Faure , Alexander Neundorf (C) 2000, 2002 Carsten Pfeiffer (C) 2010 Sebastian Trueg This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "keditlistwidget.h" #include #include #include #include #include #include #include #include #include #include class KEditListWidgetPrivate { public: KEditListWidgetPrivate(KEditListWidget *parent) : lineEdit(nullptr), editingWidget(nullptr), q(parent) { } QListView *listView; QPushButton *servUpButton, *servDownButton; QPushButton *servNewButton, *servRemoveButton; QLineEdit *lineEdit; QWidget *editingWidget; QVBoxLayout *mainLayout; QVBoxLayout *btnsLayout; QStringListModel *model; bool checkAtEntering; KEditListWidget::Buttons buttons; void init(bool check = false, KEditListWidget::Buttons buttons = KEditListWidget::All, QWidget *representationWidget = nullptr); void setEditor(QLineEdit *lineEdit, QWidget *representationWidget = nullptr); void updateButtonState(); QModelIndex selectedIndex(); private: KEditListWidget *q; }; void KEditListWidgetPrivate::init(bool check, KEditListWidget::Buttons newButtons, QWidget *representationWidget) { checkAtEntering = check; servNewButton = servRemoveButton = servUpButton = servDownButton = nullptr; q->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred)); mainLayout = new QVBoxLayout(q); mainLayout->setMargin(0); QHBoxLayout *subLayout = new QHBoxLayout; btnsLayout = new QVBoxLayout; btnsLayout->addStretch(); model = new QStringListModel(); listView = new QListView(q); listView->setModel(model); subLayout->addWidget(listView); subLayout->addLayout(btnsLayout); mainLayout->insertLayout(1, subLayout); setEditor(lineEdit, representationWidget); - buttons = nullptr; + buttons = KEditListWidget::Buttons(); q->setButtons(newButtons); q->connect(listView->selectionModel(), &QItemSelectionModel::selectionChanged, q, &KEditListWidget::slotSelectionChanged); } void KEditListWidgetPrivate::setEditor(QLineEdit *newLineEdit, QWidget *representationWidget) { if (editingWidget != lineEdit && editingWidget != representationWidget) { delete editingWidget; } if (lineEdit != newLineEdit) { delete lineEdit; } lineEdit = newLineEdit ? newLineEdit : new QLineEdit(q); editingWidget = representationWidget ? representationWidget : lineEdit; if (representationWidget) { representationWidget->setParent(q); } mainLayout->insertWidget(0, editingWidget); lineEdit->installEventFilter(q); q->connect(lineEdit, &QLineEdit::textChanged, q, &KEditListWidget::typedSomething); q->connect(lineEdit, &QLineEdit::returnPressed, q, &KEditListWidget::addItem); // maybe supplied lineedit has some text already q->typedSomething(lineEdit->text()); // fix tab ordering q->setTabOrder(editingWidget, listView); QWidget *w = listView; if (servNewButton) { q->setTabOrder(w, servNewButton); w = servNewButton; } if (servRemoveButton) { q->setTabOrder(w, servRemoveButton); w = servRemoveButton; } if (servUpButton) { q->setTabOrder(w, servUpButton); w = servUpButton; } if (servDownButton) { q->setTabOrder(w, servDownButton); w = servDownButton; } } void KEditListWidgetPrivate::updateButtonState() { const bool hasSelectedItem = selectedIndex().isValid(); // TODO: merge with enableMoveButtons() QPushButton * const buttons[3] = { servUpButton, servDownButton, servRemoveButton }; for (QPushButton *button : buttons) { if (button) { // keep focus in widget if (!hasSelectedItem && button->hasFocus()) { lineEdit->setFocus(Qt::OtherFocusReason); } button->setEnabled(hasSelectedItem); } } } QModelIndex KEditListWidgetPrivate::selectedIndex() { QItemSelectionModel *selection = listView->selectionModel(); const QModelIndexList selectedIndexes = selection->selectedIndexes(); if (!selectedIndexes.isEmpty() && selectedIndexes[0].isValid()) { return selectedIndexes[0]; } else { return QModelIndex(); } } class KEditListWidget::CustomEditorPrivate { public: CustomEditorPrivate(KEditListWidget::CustomEditor *q): q(q), representationWidget(nullptr), lineEdit(nullptr) {} KEditListWidget::CustomEditor *q; QWidget *representationWidget; QLineEdit *lineEdit; }; KEditListWidget::CustomEditor::CustomEditor() : d(new CustomEditorPrivate(this)) { } KEditListWidget::CustomEditor::CustomEditor(QWidget *repWidget, QLineEdit *edit) : d(new CustomEditorPrivate(this)) { d->representationWidget = repWidget; d->lineEdit = edit; } KEditListWidget::CustomEditor::CustomEditor(QComboBox *combo) : d(new CustomEditorPrivate(this)) { d->representationWidget = combo; d->lineEdit = qobject_cast(combo->lineEdit()); Q_ASSERT(d->lineEdit); } KEditListWidget::CustomEditor::~CustomEditor() { delete d; } void KEditListWidget::CustomEditor::setRepresentationWidget(QWidget *repWidget) { d->representationWidget = repWidget; } void KEditListWidget::CustomEditor::setLineEdit(QLineEdit *edit) { d->lineEdit = edit; } QWidget *KEditListWidget::CustomEditor::representationWidget() const { return d->representationWidget; } QLineEdit *KEditListWidget::CustomEditor::lineEdit() const { return d->lineEdit; } KEditListWidget::KEditListWidget(QWidget *parent) : QWidget(parent), d(new KEditListWidgetPrivate(this)) { d->init(); } KEditListWidget::KEditListWidget(const CustomEditor &custom, QWidget *parent, bool checkAtEntering, Buttons buttons) : QWidget(parent), d(new KEditListWidgetPrivate(this)) { d->lineEdit = custom.lineEdit(); d->init(checkAtEntering, buttons, custom.representationWidget()); } KEditListWidget::~KEditListWidget() { delete d; } void KEditListWidget::setCustomEditor(const CustomEditor &editor) { d->setEditor(editor.lineEdit(), editor.representationWidget()); } QListView *KEditListWidget::listView() const { return d->listView; } QLineEdit *KEditListWidget::lineEdit() const { return d->lineEdit; } QPushButton *KEditListWidget::addButton() const { return d->servNewButton; } QPushButton *KEditListWidget::removeButton() const { return d->servRemoveButton; } QPushButton *KEditListWidget::upButton() const { return d->servUpButton; } QPushButton *KEditListWidget::downButton() const { return d->servDownButton; } int KEditListWidget::count() const { return int(d->model->rowCount()); } void KEditListWidget::setButtons(Buttons buttons) { if (d->buttons == buttons) { return; } if ((buttons & Add) && !d->servNewButton) { d->servNewButton = new QPushButton(QIcon::fromTheme(QStringLiteral("list-add")), tr("&Add"), this); d->servNewButton->setEnabled(false); d->servNewButton->show(); connect(d->servNewButton, &QAbstractButton::clicked, this, &KEditListWidget::addItem); d->btnsLayout->insertWidget(0, d->servNewButton); } else if ((buttons & Add) == 0 && d->servNewButton) { delete d->servNewButton; d->servNewButton = nullptr; } if ((buttons & Remove) && !d->servRemoveButton) { d->servRemoveButton = new QPushButton(QIcon::fromTheme(QStringLiteral("list-remove")), tr("&Remove"), this); d->servRemoveButton->setEnabled(false); d->servRemoveButton->show(); connect(d->servRemoveButton, &QAbstractButton::clicked, this, &KEditListWidget::removeItem); d->btnsLayout->insertWidget(1, d->servRemoveButton); } else if ((buttons & Remove) == 0 && d->servRemoveButton) { delete d->servRemoveButton; d->servRemoveButton = nullptr; } if ((buttons & UpDown) && !d->servUpButton) { d->servUpButton = new QPushButton(QIcon::fromTheme(QStringLiteral("arrow-up")), tr("Move &Up"), this); d->servUpButton->setEnabled(false); d->servUpButton->show(); connect(d->servUpButton, &QAbstractButton::clicked, this, &KEditListWidget::moveItemUp); d->servDownButton = new QPushButton(QIcon::fromTheme(QStringLiteral("arrow-down")), tr("Move &Down"), this); d->servDownButton->setEnabled(false); d->servDownButton->show(); connect(d->servDownButton, &QAbstractButton::clicked, this, &KEditListWidget::moveItemDown); d->btnsLayout->insertWidget(2, d->servUpButton); d->btnsLayout->insertWidget(3, d->servDownButton); } else if ((buttons & UpDown) == 0 && d->servUpButton) { delete d->servUpButton; d->servUpButton = nullptr; delete d->servDownButton; d->servDownButton = nullptr; } d->buttons = buttons; } void KEditListWidget::setCheckAtEntering(bool check) { d->checkAtEntering = check; } bool KEditListWidget::checkAtEntering() { return d->checkAtEntering; } void KEditListWidget::typedSomething(const QString &text) { if (currentItem() >= 0) { if (currentText() != d->lineEdit->text()) { // IMHO changeItem() shouldn't do anything with the value // of currentItem() ... like changing it or emitting signals ... // but TT disagree with me on this one (it's been that way since ages ... grrr) bool block = d->listView->signalsBlocked(); d->listView->blockSignals(true); QModelIndex currentIndex = d->selectedIndex(); if (currentIndex.isValid()) { d->model->setData(currentIndex, text); } d->listView->blockSignals(block); emit changed(); } } if (!d->servNewButton) { return; } if (!d->lineEdit->hasAcceptableInput()) { d->servNewButton->setEnabled(false); return; } if (!d->checkAtEntering) { d->servNewButton->setEnabled(!text.isEmpty()); } else { if (text.isEmpty()) { d->servNewButton->setEnabled(false); } else { QStringList list = d->model->stringList(); bool enable = !list.contains(text, Qt::CaseSensitive); d->servNewButton->setEnabled(enable); } } } void KEditListWidget::moveItemUp() { if (!d->listView->isEnabled()) { QApplication::beep(); return; } QModelIndex index = d->selectedIndex(); if (index.isValid()) { if (index.row() == 0) { QApplication::beep(); return; } QModelIndex aboveIndex = d->model->index(index.row() - 1, index.column()); QString tmp = d->model->data(aboveIndex, Qt::DisplayRole).toString(); d->model->setData(aboveIndex, d->model->data(index, Qt::DisplayRole)); d->model->setData(index, tmp); d->listView->selectionModel()->select(index, QItemSelectionModel::Deselect); d->listView->selectionModel()->select(aboveIndex, QItemSelectionModel::Select); } emit changed(); } void KEditListWidget::moveItemDown() { if (!d->listView->isEnabled()) { QApplication::beep(); return; } QModelIndex index = d->selectedIndex(); if (index.isValid()) { if (index.row() == d->model->rowCount() - 1) { QApplication::beep(); return; } QModelIndex belowIndex = d->model->index(index.row() + 1, index.column()); QString tmp = d->model->data(belowIndex, Qt::DisplayRole).toString(); d->model->setData(belowIndex, d->model->data(index, Qt::DisplayRole)); d->model->setData(index, tmp); d->listView->selectionModel()->select(index, QItemSelectionModel::Deselect); d->listView->selectionModel()->select(belowIndex, QItemSelectionModel::Select); } emit changed(); } void KEditListWidget::addItem() { // when checkAtEntering is true, the add-button is disabled, but this // slot can still be called through Key_Return/Key_Enter. So we guard // against this. if (!d->servNewButton || !d->servNewButton->isEnabled()) { return; } QModelIndex currentIndex = d->selectedIndex(); const QString ¤tTextLE = d->lineEdit->text(); bool alreadyInList(false); //if we didn't check for dupes at the inserting we have to do it now if (!d->checkAtEntering) { // first check current item instead of dumb iterating the entire list if (currentIndex.isValid()) { if (d->model->data(currentIndex, Qt::DisplayRole).toString() == currentTextLE) { alreadyInList = true; } } else { alreadyInList = d->model->stringList().contains(currentTextLE, Qt::CaseSensitive); } } if (d->servNewButton) { // prevent losing the focus by it being moved outside of this widget // as well as support the user workflow a little by moving the focus // to the lineedit. chances are that users will add some items consecutively, // so this will save a manual focus change, and it is also consistent // to what happens on the click on the Remove button if (d->servNewButton->hasFocus()) { d->lineEdit->setFocus(Qt::OtherFocusReason); } d->servNewButton->setEnabled(false); } bool block = d->lineEdit->signalsBlocked(); d->lineEdit->blockSignals(true); d->lineEdit->clear(); d->lineEdit->blockSignals(block); d->listView->selectionModel()->setCurrentIndex(currentIndex, QItemSelectionModel::Deselect); if (!alreadyInList) { block = d->listView->signalsBlocked(); if (currentIndex.isValid()) { d->model->setData(currentIndex, currentTextLE); } else { QStringList lst; lst << currentTextLE; lst << d->model->stringList(); d->model->setStringList(lst); } emit changed(); emit added(currentTextLE); // TODO: pass the index too } d->updateButtonState(); } int KEditListWidget::currentItem() const { QModelIndex selectedIndex = d->selectedIndex(); if (selectedIndex.isValid()) { return selectedIndex.row(); } else { return -1; } } void KEditListWidget::removeItem() { QModelIndex currentIndex = d->selectedIndex(); if (!currentIndex.isValid()) { return; } if (currentIndex.row() >= 0) { // prevent losing the focus by it being moved outside of this widget // as well as support the user workflow a little by moving the focus // to the lineedit. chances are that users will add some item next, // so this will save a manual focus change, if (d->servRemoveButton && d->servRemoveButton->hasFocus()) { d->lineEdit->setFocus(Qt::OtherFocusReason); } QString removedText = d->model->data(currentIndex, Qt::DisplayRole).toString(); d->model->removeRows(currentIndex.row(), 1); d->listView->selectionModel()->clear(); emit changed(); emit removed(removedText); } d->updateButtonState(); } void KEditListWidget::enableMoveButtons(const QModelIndex &newIndex, const QModelIndex &) { int index = newIndex.row(); // Update the lineEdit when we select a different line. if (currentText() != d->lineEdit->text()) { d->lineEdit->setText(currentText()); } bool moveEnabled = d->servUpButton && d->servDownButton; if (moveEnabled) { if (d->model->rowCount() <= 1) { d->servUpButton->setEnabled(false); d->servDownButton->setEnabled(false); } else if (index == (d->model->rowCount() - 1)) { d->servUpButton->setEnabled(true); d->servDownButton->setEnabled(false); } else if (index == 0) { d->servUpButton->setEnabled(false); d->servDownButton->setEnabled(true); } else { d->servUpButton->setEnabled(true); d->servDownButton->setEnabled(true); } } if (d->servRemoveButton) { d->servRemoveButton->setEnabled(true); } } void KEditListWidget::clear() { d->lineEdit->clear(); d->model->setStringList(QStringList()); emit changed(); } void KEditListWidget::insertStringList(const QStringList &list, int index) { QStringList content = d->model->stringList(); if (index < 0) { content += list; } else for (int i = 0, j = index; i < list.count(); ++i, ++j) { content.insert(j, list[ i ]); } d->model->setStringList(content); } void KEditListWidget::insertItem(const QString &text, int index) { QStringList list = d->model->stringList(); if (index < 0) { list.append(text); } else { list.insert(index, text); } d->model->setStringList(list); } QString KEditListWidget::text(int index) const { const QStringList list = d->model->stringList(); return list[ index ]; } QString KEditListWidget::currentText() const { QModelIndex index = d->selectedIndex(); if (!index.isValid()) { return QString(); } else { return text(index.row()); } } QStringList KEditListWidget::items() const { return d->model->stringList(); } void KEditListWidget::setItems(const QStringList &items) { d->model->setStringList(items); } KEditListWidget::Buttons KEditListWidget::buttons() const { return d->buttons; } void KEditListWidget::slotSelectionChanged(const QItemSelection &, const QItemSelection &) { d->updateButtonState(); QModelIndex index = d->selectedIndex(); enableMoveButtons(index, QModelIndex()); if (index.isValid()) { d->lineEdit->setFocus(Qt::OtherFocusReason); } } bool KEditListWidget::eventFilter(QObject *o, QEvent *e) { if (o == d->lineEdit && e->type() == QEvent::KeyPress) { QKeyEvent *keyEvent = (QKeyEvent *)e; if (keyEvent->key() == Qt::Key_Down || keyEvent->key() == Qt::Key_Up) { return ((QObject *)d->listView)->event(e); } else if (keyEvent->key() == Qt::Key_Return || keyEvent->key() == Qt::Key_Enter) { return true; } } return false; } diff --git a/src/kfontrequester.cpp b/src/kfontrequester.cpp index 8d7abd5..96bf01d 100644 --- a/src/kfontrequester.cpp +++ b/src/kfontrequester.cpp @@ -1,237 +1,237 @@ /* Copyright (C) 2003 Nadeem Hasan This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kfontrequester.h" #include "fonthelpers_p.h" #include #include #include #include #include #include #include #include #include // Determine if the font with given properties is available on the system, // otherwise find and return the best fitting combination. static QFont nearestExistingFont(const QFont &font) { QFontDatabase dbase; // Initialize font data accoring to given font object. QString family = font.family(); QString style = dbase.styleString(font); qreal size = font.pointSizeF(); // Check if the family exists. const QStringList families = dbase.families(); if (!families.contains(family)) { // Chose another family. family = QFontInfo(font).family(); // the nearest match if (!families.contains(family)) { family = families.count() ? families.at(0) : QStringLiteral("fixed"); } } // Check if the family has the requested style. // Easiest by piping it through font selection in the database. QString retStyle = dbase.styleString(dbase.font(family, style, 10)); style = retStyle; // Check if the family has the requested size. // Only for bitmap fonts. if (!dbase.isSmoothlyScalable(family, style)) { QList sizes = dbase.smoothSizes(family, style); if (!sizes.contains(size)) { // Find nearest available size. int mindiff = 1000; int refsize = size; Q_FOREACH (int lsize, sizes) { int diff = qAbs(refsize - lsize); if (mindiff > diff) { mindiff = diff; size = lsize; } } } } // Select the font with confirmed properties. QFont result = dbase.font(family, style, int(size)); if (dbase.isSmoothlyScalable(family, style) && result.pointSize() == floor(size)) { result.setPointSizeF(size); } return result; } class KFontRequester::KFontRequesterPrivate { public: KFontRequesterPrivate(KFontRequester *q): q(q) {} void displaySampleText(); void setToolTip(); void _k_buttonClicked(); KFontRequester *q; bool m_onlyFixed; QString m_sampleText, m_title; QLabel *m_sampleLabel; QPushButton *m_button; QFont m_selFont; }; KFontRequester::KFontRequester(QWidget *parent, bool onlyFixed) : QWidget(parent), d(new KFontRequesterPrivate(this)) { d->m_onlyFixed = onlyFixed; QHBoxLayout *layout = new QHBoxLayout(this); layout->setMargin(0); d->m_sampleLabel = new QLabel(this); d->m_button = new QPushButton(tr("Choose..."), this); d->m_sampleLabel->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); setFocusProxy(d->m_button); setFocusPolicy(d->m_button->focusPolicy()); layout->addWidget(d->m_sampleLabel, 1); layout->addWidget(d->m_button); connect(d->m_button, SIGNAL(clicked()), SLOT(_k_buttonClicked())); d->displaySampleText(); d->setToolTip(); } KFontRequester::~KFontRequester() { delete d; } QFont KFontRequester::font() const { return d->m_selFont; } bool KFontRequester::isFixedOnly() const { return d->m_onlyFixed; } QString KFontRequester::sampleText() const { return d->m_sampleText; } QString KFontRequester::title() const { return d->m_title; } QLabel *KFontRequester::label() const { return d->m_sampleLabel; } QPushButton *KFontRequester::button() const { return d->m_button; } void KFontRequester::setFont(const QFont &font, bool onlyFixed) { d->m_selFont = nearestExistingFont(font); d->m_onlyFixed = onlyFixed; d->displaySampleText(); emit fontSelected(d->m_selFont); } void KFontRequester::setSampleText(const QString &text) { d->m_sampleText = text; d->displaySampleText(); } void KFontRequester::setTitle(const QString &title) { d->m_title = title; d->setToolTip(); } void KFontRequester::KFontRequesterPrivate::_k_buttonClicked() { - QFontDialog::FontDialogOptions flags = nullptr; + QFontDialog::FontDialogOptions flags; if (m_onlyFixed) { flags = QFontDialog::MonospacedFonts; } bool ok = false; QFont font = QFontDialog::getFont(&ok, m_selFont, q->parentWidget(), QString(), flags); if (ok) { m_selFont = font; displaySampleText(); emit q->fontSelected(m_selFont); } } void KFontRequester::KFontRequesterPrivate::displaySampleText() { m_sampleLabel->setFont(m_selFont); qreal size = m_selFont.pointSizeF(); if (size == -1) { size = m_selFont.pixelSize(); } if (m_sampleText.isEmpty()) { QString family = translateFontName(m_selFont.family()); m_sampleLabel->setText(QStringLiteral("%1 %2").arg(family).arg(size)); } else { m_sampleLabel->setText(m_sampleText); } } void KFontRequester::KFontRequesterPrivate::setToolTip() { m_button->setToolTip(tr("Click to select a font")); m_sampleLabel->setToolTip(QString()); m_sampleLabel->setWhatsThis(QString()); if (m_title.isNull()) { m_sampleLabel->setToolTip(tr("Preview of the selected font")); m_sampleLabel->setWhatsThis(tr("This is a preview of the selected font. You can change it" " by clicking the \"Choose...\" button.")); } else { m_sampleLabel->setToolTip(tr("Preview of the \"%1\" font").arg(m_title)); m_sampleLabel->setWhatsThis(tr("This is a preview of the \"%1\" font. You can change it" " by clicking the \"Choose...\" button.").arg(m_title)); } } #include "moc_kfontrequester.cpp" diff --git a/src/kpagedialog.h b/src/kpagedialog.h index eb9367b..77e50bd 100644 --- a/src/kpagedialog.h +++ b/src/kpagedialog.h @@ -1,285 +1,285 @@ /* * This file is part of the KDE Libraries * Copyright (C) 1999-2001 Mirko Boehm (mirko@kde.org) and * Espen Sand (espen@kde.org) * Holger Freyther * 2005-2006 Olivier Goffart * 2006 Tobias Koenig * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */ #ifndef KPAGEDIALOG_H #define KPAGEDIALOG_H #include #include #include class KPageDialogPrivate; /** * @class KPageDialog kpagedialog.h KPageDialog * * @short A dialog base class which can handle multiple pages. * * This class provides a dialog base class which handles multiple * pages and allows the user to switch between these pages in * different ways. * * Currently, @p Auto, @p Plain, @p List, @p Tree and @p Tabbed face * types are available (cmp. KPageView). * * Example:\n * * \code * UrlDialog::UrlDialog( QWidget *parent ) * : KPageDialog( parent ) * { * setFaceType( List ); * * QLabel *label = new QLabel( "Test Page" ); * addPage( label, i18n( "My Test Page" ) ); * * label = new QLabel( "Second Test Page" ); * KPageWidgetItem *page = new KPageWidgetItem( label, i18n( "My Second Test Page" ) ); * page->setHeader( i18n( "My header string" ) ); * page->setIcon( QIcon::fromTheme( "file" ) ); * * addPage( page ); * } * \endcode * * @author Tobias Koenig (tokoe@kde.org) */ class KWIDGETSADDONS_EXPORT KPageDialog : public QDialog { Q_OBJECT Q_DECLARE_PRIVATE(KPageDialog) public: /** * The face types supported. */ enum FaceType { /** * A dialog with a face based on the structure of the available pages. * If only a single page is added, the dialog behaves like * in @c Plain mode, with multiple pages without sub pages * it behaves like in @c List mode and like in @c Tree mode otherwise. */ Auto = KPageView::Auto, /** * A normal dialog */ Plain = KPageView::Plain, /** * A dialog with an icon list on the left side and a * representation of the contents on the right side */ List = KPageView::List, /** * A dialog with a tree on the left side and a * representation of the contents on the right side */ Tree = KPageView::Tree, /** * A dialog with a tab bar above the representation * of the contents */ Tabbed = KPageView::Tabbed }; public: /** * Creates a new page dialog. */ - explicit KPageDialog(QWidget *parent = nullptr, Qt::WindowFlags flags = nullptr); + explicit KPageDialog(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags()); /** * Destroys the page dialog. */ ~KPageDialog(); /** * Sets the face type of the dialog. */ void setFaceType(FaceType faceType); /** * Adds a new top level page to the dialog. * * @param widget The widget of the page. * @param name The name which is displayed in the navigation view. * * @returns The associated KPageWidgetItem. */ KPageWidgetItem *addPage(QWidget *widget, const QString &name); /** * Adds a new top level page to the dialog. * * @param item The KPageWidgetItem which describes the page. */ void addPage(KPageWidgetItem *item); /** * Inserts a new page in the dialog. * * @param before The new page will be insert before this KPageWidgetItem * on the same level in hierarchy. * @param widget The widget of the page. * @param name The name which is displayed in the navigation view. * * @returns The associated KPageWidgetItem. */ KPageWidgetItem *insertPage(KPageWidgetItem *before, QWidget *widget, const QString &name); /** * Inserts a new page in the dialog. * * @param before The new page will be insert before this KPageWidgetItem * on the same level in hierarchy. * * @param item The KPageWidgetItem which describes the page. */ void insertPage(KPageWidgetItem *before, KPageWidgetItem *item); /** * Inserts a new sub page in the dialog. * * @param parent The new page will be insert as child of this KPageWidgetItem. * @param widget The widget of the page. * @param name The name which is displayed in the navigation view. * * @returns The associated KPageWidgetItem. */ KPageWidgetItem *addSubPage(KPageWidgetItem *parent, QWidget *widget, const QString &name); /** * Inserts a new sub page in the dialog. * * @param parent The new page will be insert as child of this KPageWidgetItem. * * @param item The KPageWidgetItem which describes the page. */ void addSubPage(KPageWidgetItem *parent, KPageWidgetItem *item); /** * Removes the page associated with the given KPageWidgetItem. */ void removePage(KPageWidgetItem *item); /** * Sets the page which is associated with the given KPageWidgetItem to * be the current page and emits the currentPageChanged() signal. */ void setCurrentPage(KPageWidgetItem *item); /** * Returns the KPageWidgetItem for the current page or a null pointer if there is no * current page. */ KPageWidgetItem *currentPage() const; /** * Sets the collection of standard buttons displayed by this dialog. */ void setStandardButtons(QDialogButtonBox::StandardButtons buttons); /** * Returns the QPushButton corresponding to the standard button which, or a null pointer if the standard * button doesn't exist in this dialog. */ QPushButton *button(QDialogButtonBox::StandardButton which) const; /** * Set an action button. */ void addActionButton(QAbstractButton *button); Q_SIGNALS: /** * This signal is emitted whenever the current page has changed. * * @param current The new current page or a null pointer if no current page is available. * @param before The page that was current before the new current page has changed. */ void currentPageChanged(KPageWidgetItem *current, KPageWidgetItem *before); /** * This signal is emitted whenever a page has been removed. * * @param page The page which has been removed **/ void pageRemoved(KPageWidgetItem *page); protected: /** * This constructor can be used by subclasses to provide a custom page widget. * * \param widget The KPageWidget object will be reparented to this object, so you can create * it without parent and you are not allowed to delete it. */ - KPageDialog(KPageWidget *widget, QWidget *parent, Qt::WindowFlags flags = nullptr); - KPageDialog(KPageDialogPrivate &dd, KPageWidget *widget, QWidget *parent, Qt::WindowFlags flags = nullptr); + KPageDialog(KPageWidget *widget, QWidget *parent, Qt::WindowFlags flags = Qt::WindowFlags()); + KPageDialog(KPageDialogPrivate &dd, KPageWidget *widget, QWidget *parent, Qt::WindowFlags flags = Qt::WindowFlags()); /** * Returns the page widget of the dialog or a null pointer if no page widget is set. */ KPageWidget *pageWidget(); /** * Returns the page widget of the dialog or a null pointer if no page widget is set. */ const KPageWidget *pageWidget() const; /** * Set the page widget of the dialog. * * @note the previous pageWidget will be deleted. * * @param widget The KPageWidget object will be reparented to this object, so you can create * it without parent and you are not allowed to delete it. */ void setPageWidget(KPageWidget *widget); /** * Returns the button box of the dialog or a null pointer if no button box is set. */ QDialogButtonBox *buttonBox(); /** * Returns the button box of the dialog or a null pointer if no button box is set. */ const QDialogButtonBox *buttonBox() const; /** * Set the button box of the dialog * * @note the previous buttonBox will be deleted. * * @param box The QDialogButtonBox object will be reparented to this object, so you can create * it without parent and you are not allowed to delete it. */ void setButtonBox(QDialogButtonBox *box); protected: KPageDialogPrivate *const d_ptr; }; #endif diff --git a/src/kpagewidgetmodel.cpp b/src/kpagewidgetmodel.cpp index e1d4882..1cf39b7 100644 --- a/src/kpagewidgetmodel.cpp +++ b/src/kpagewidgetmodel.cpp @@ -1,574 +1,574 @@ /* This file is part of the KDE Libraries Copyright (C) 2006 Tobias Koenig (tokoe@kde.org) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kpagewidgetmodel.h" #include "kpagewidgetmodel_p.h" #include "loggingcategory.h" #include #include #include class KPageWidgetItem::Private { public: Private() : checkable(false), checked(false), enabled(true) { } ~Private() { delete widget; widget = nullptr; } QString name; QString header; QIcon icon; QPointer widget; bool checkable : 1; bool checked : 1; bool enabled : 1; }; KPageWidgetItem::KPageWidgetItem(QWidget *widget) : QObject(nullptr), d(new Private) { d->widget = widget; /** * Hide the widget, otherwise when the widget has this KPageView as * parent the widget is shown outside the QStackedWidget if the page * was not selected ( and reparented ) yet. */ if (d->widget) { d->widget->hide(); } } KPageWidgetItem::KPageWidgetItem(QWidget *widget, const QString &name) : QObject(nullptr), d(new Private) { d->widget = widget; d->name = name; /** * Hide the widget, otherwise when the widget has this KPageView as * parent the widget is shown outside the QStackedWidget if the page * was not selected ( and reparented ) yet. */ if (d->widget) { d->widget->hide(); } } KPageWidgetItem::~KPageWidgetItem() { delete d; } void KPageWidgetItem::setEnabled(bool enabled) { d->enabled = enabled; if (d->widget) { d->widget->setEnabled(enabled); } emit changed(); } bool KPageWidgetItem::isEnabled() const { return d->enabled; } QWidget *KPageWidgetItem::widget() const { return d->widget; } void KPageWidgetItem::setName(const QString &name) { d->name = name; emit changed(); } QString KPageWidgetItem::name() const { return d->name; } void KPageWidgetItem::setHeader(const QString &header) { d->header = header; emit changed(); } QString KPageWidgetItem::header() const { return d->header; } void KPageWidgetItem::setIcon(const QIcon &icon) { d->icon = icon; emit changed(); } QIcon KPageWidgetItem::icon() const { return d->icon; } void KPageWidgetItem::setCheckable(bool checkable) { d->checkable = checkable; emit changed(); } bool KPageWidgetItem::isCheckable() const { return d->checkable; } void KPageWidgetItem::setChecked(bool checked) { d->checked = checked; emit toggled(checked); emit changed(); } bool KPageWidgetItem::isChecked() const { return d->checked; } PageItem::PageItem(KPageWidgetItem *pageWidgetItem, PageItem *parent) : mPageWidgetItem(pageWidgetItem), mParentItem(parent) { } PageItem::~PageItem() { delete mPageWidgetItem; mPageWidgetItem = nullptr; qDeleteAll(mChildItems); } void PageItem::appendChild(PageItem *item) { mChildItems.append(item); } void PageItem::insertChild(int row, PageItem *item) { mChildItems.insert(row, item); } void PageItem::removeChild(int row) { mChildItems.removeAt(row); } PageItem *PageItem::child(int row) { return mChildItems.value(row); } int PageItem::childCount() const { return mChildItems.count(); } int PageItem::columnCount() const { return 1; } PageItem *PageItem::parent() { return mParentItem; } int PageItem::row() const { if (mParentItem) { return mParentItem->mChildItems.indexOf(const_cast(this)); } return 0; } KPageWidgetItem *PageItem::pageWidgetItem() const { return mPageWidgetItem; } PageItem *PageItem::findChild(const KPageWidgetItem *item) { if (mPageWidgetItem == item) { return this; } for (int i = 0; i < mChildItems.count(); ++i) { PageItem *pageItem = mChildItems[ i ]->findChild(item); if (pageItem) { return pageItem; } } return nullptr; } void PageItem::dump(int indent) { QString prefix; for (int i = 0; i < indent; ++i) { prefix.append(QStringLiteral(" ")); } const QString name = (mPageWidgetItem ? mPageWidgetItem->name() : QStringLiteral("root")); qCDebug(KWidgetsAddonsLog, "%s (%p)", qPrintable(QString(QStringLiteral("%1%2")).arg(prefix, name)), (void *)this); for (int i = 0; i < mChildItems.count(); ++i) { mChildItems[ i ]->dump(indent + 2); } } KPageWidgetModel::KPageWidgetModel(QObject *parent) : KPageModel(*new KPageWidgetModelPrivate, parent) { } KPageWidgetModel::~KPageWidgetModel() { } int KPageWidgetModel::columnCount(const QModelIndex &) const { return 1; } QVariant KPageWidgetModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) { return QVariant(); } PageItem *item = static_cast(index.internalPointer()); if (role == Qt::DisplayRole) { return QVariant(item->pageWidgetItem()->name()); } else if (role == Qt::DecorationRole) { return QVariant(item->pageWidgetItem()->icon()); } else if (role == HeaderRole) { return QVariant(item->pageWidgetItem()->header()); } else if (role == WidgetRole) { return QVariant::fromValue(item->pageWidgetItem()->widget()); } else if (role == Qt::CheckStateRole) { if (item->pageWidgetItem()->isCheckable()) { return (item->pageWidgetItem()->isChecked() ? Qt::Checked : Qt::Unchecked); } else { return QVariant(); } } else { return QVariant(); } } bool KPageWidgetModel::setData(const QModelIndex &index, const QVariant &value, int role) { if (!index.isValid()) { return false; } if (role != Qt::CheckStateRole) { return false; } PageItem *item = static_cast(index.internalPointer()); if (!item) { return false; } if (!item->pageWidgetItem()->isCheckable()) { return false; } if (value.toInt() == Qt::Checked) { item->pageWidgetItem()->setChecked(true); } else { item->pageWidgetItem()->setChecked(false); } return true; } Qt::ItemFlags KPageWidgetModel::flags(const QModelIndex &index) const { if (!index.isValid()) { - return nullptr; + return Qt::NoItemFlags; } Qt::ItemFlags flags = Qt::ItemIsSelectable; PageItem *item = static_cast(index.internalPointer()); if (item->pageWidgetItem()->isCheckable()) { flags |= Qt::ItemIsUserCheckable; } if (item->pageWidgetItem()->isEnabled()) { flags |= Qt::ItemIsEnabled; } return flags; } QModelIndex KPageWidgetModel::index(int row, int column, const QModelIndex &parent) const { PageItem *parentItem; if (parent.isValid()) { parentItem = static_cast(parent.internalPointer()); } else { parentItem = d_func()->rootItem; } PageItem *childItem = parentItem->child(row); if (childItem) { return createIndex(row, column, childItem); } else { return QModelIndex(); } } QModelIndex KPageWidgetModel::parent(const QModelIndex &index) const { if (!index.isValid()) { return QModelIndex(); } PageItem *item = static_cast(index.internalPointer()); PageItem *parentItem = item->parent(); if (parentItem == d_func()->rootItem) { return QModelIndex(); } else { return createIndex(parentItem->row(), 0, parentItem); } } int KPageWidgetModel::rowCount(const QModelIndex &parent) const { PageItem *parentItem; if (!parent.isValid()) { parentItem = d_func()->rootItem; } else { parentItem = static_cast(parent.internalPointer()); } return parentItem->childCount(); } KPageWidgetItem *KPageWidgetModel::addPage(QWidget *widget, const QString &name) { KPageWidgetItem *item = new KPageWidgetItem(widget, name); addPage(item); return item; } void KPageWidgetModel::addPage(KPageWidgetItem *item) { emit layoutAboutToBeChanged(); Q_D(KPageWidgetModel); connect(item, SIGNAL(changed()), this, SLOT(_k_itemChanged())); connect(item, SIGNAL(toggled(bool)), this, SLOT(_k_itemToggled(bool))); // The row to be inserted int row = d->rootItem->childCount(); beginInsertRows(QModelIndex(), row, row); PageItem *pageItem = new PageItem(item, d->rootItem); d->rootItem->appendChild(pageItem); endInsertRows(); emit layoutChanged(); } KPageWidgetItem *KPageWidgetModel::insertPage(KPageWidgetItem *before, QWidget *widget, const QString &name) { KPageWidgetItem *item = new KPageWidgetItem(widget, name); insertPage(before, item); return item; } void KPageWidgetModel::insertPage(KPageWidgetItem *before, KPageWidgetItem *item) { PageItem *beforePageItem = d_func()->rootItem->findChild(before); if (!beforePageItem) { qCDebug(KWidgetsAddonsLog, "Invalid KPageWidgetItem passed!"); return; } emit layoutAboutToBeChanged(); connect(item, SIGNAL(changed()), this, SLOT(_k_itemChanged())); connect(item, SIGNAL(toggled(bool)), this, SLOT(_k_itemToggled(bool))); PageItem *parent = beforePageItem->parent(); // The row to be inserted int row = beforePageItem->row(); QModelIndex index; if (parent != d_func()->rootItem) { index = createIndex(parent->row(), 0, parent); } beginInsertRows(index, row, row); PageItem *newPageItem = new PageItem(item, parent); parent->insertChild(row, newPageItem); endInsertRows(); emit layoutChanged(); } KPageWidgetItem *KPageWidgetModel::addSubPage(KPageWidgetItem *parent, QWidget *widget, const QString &name) { KPageWidgetItem *item = new KPageWidgetItem(widget, name); addSubPage(parent, item); return item; } void KPageWidgetModel::addSubPage(KPageWidgetItem *parent, KPageWidgetItem *item) { PageItem *parentPageItem = d_func()->rootItem->findChild(parent); if (!parentPageItem) { qCDebug(KWidgetsAddonsLog, "Invalid KPageWidgetItem passed!"); return; } emit layoutAboutToBeChanged(); connect(item, SIGNAL(changed()), this, SLOT(_k_itemChanged())); connect(item, SIGNAL(toggled(bool)), this, SLOT(_k_itemToggled(bool))); // The row to be inserted int row = parentPageItem->childCount(); QModelIndex index; if (parentPageItem != d_func()->rootItem) { index = createIndex(parentPageItem->row(), 0, parentPageItem); } beginInsertRows(index, row, row); PageItem *newPageItem = new PageItem(item, parentPageItem); parentPageItem->appendChild(newPageItem); endInsertRows(); emit layoutChanged(); } void KPageWidgetModel::removePage(KPageWidgetItem *item) { if (!item) { return; } Q_D(KPageWidgetModel); PageItem *pageItem = d->rootItem->findChild(item); if (!pageItem) { qCDebug(KWidgetsAddonsLog, "Invalid KPageWidgetItem passed!"); return; } emit layoutAboutToBeChanged(); disconnect(item, SIGNAL(changed()), this, SLOT(_k_itemChanged())); disconnect(item, SIGNAL(toggled(bool)), this, SLOT(_k_itemToggled(bool))); PageItem *parentPageItem = pageItem->parent(); int row = parentPageItem->row(); QModelIndex index; if (parentPageItem != d->rootItem) { index = createIndex(row, 0, parentPageItem); } beginRemoveRows(index, pageItem->row(), pageItem->row()); parentPageItem->removeChild(pageItem->row()); delete pageItem; endRemoveRows(); emit layoutChanged(); } KPageWidgetItem *KPageWidgetModel::item(const QModelIndex &index) const { if (!index.isValid()) { return nullptr; } PageItem *item = static_cast(index.internalPointer()); if (!item) { return nullptr; } return item->pageWidgetItem(); } QModelIndex KPageWidgetModel::index(const KPageWidgetItem *item) const { if (!item) { return QModelIndex(); } const PageItem *pageItem = d_func()->rootItem->findChild(item); if (!pageItem) { return QModelIndex(); } return createIndex(pageItem->row(), 0, (void *)pageItem); } #include "moc_kpagewidgetmodel.cpp" diff --git a/src/kpassworddialog.h b/src/kpassworddialog.h index 217f8d9..a5d7cfe 100644 --- a/src/kpassworddialog.h +++ b/src/kpassworddialog.h @@ -1,324 +1,324 @@ /* This file is part of the KDE libraries Copyright (C) 2000 David Faure Copyright (C) 2000 Dawit Alemayehu Copyright (C) 2007 Olivier Goffart This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KPASSWORDDIALOG_H #define KPASSWORDDIALOG_H #include #include #include #include /** * @class KPasswordDialog kpassworddialog.h KPasswordDialog * * A dialog for requesting a password and optionaly a login from the end user. * * \section usage Usage Example * * Requesting a simple password, assynchronous * * \code * KPasswordDialog *dlg = new KPasswordDialog( parent ); * dlg->setPrompt(i18n("Enter a password")); * connect( dlg, SIGNAL( gotPassword( const QString& , bool ) ) , this, SLOT( setPassword( const QString &) ) ); * connect( dlg, SIGNAL( rejected() ) , this, SLOT( slotCancel() ) ); * dlg->show(); * \endcode * * Requesting a login and a password, synchronous * * \code * KPasswordDialog dlg(parent, KPasswordDialog::ShowUsernameLine); * dlg.setPrompt(i18n("Enter a login and a password")); * if( !dlg.exec() ) * return; //the user canceled * use( dlg.username() , dlg.password() ); * \endcode * * \image html kpassworddialog.png "KPasswordDialog" * * @short dialog for requesting login and password from the end user */ class KWIDGETSADDONS_EXPORT KPasswordDialog : public QDialog { Q_OBJECT public: enum KPasswordDialogFlag { NoFlags = 0x00, /** * If this flag is set, the "keep this password" checkbox will been shown, * otherwise, it will not be shown and keepPassword will have no effect */ ShowKeepPassword = 0x01, /** * If this flag is set, there will be an additional line to let the user enter his login. * otherwise, only the password line will be shown. */ ShowUsernameLine = 0x02, /** * If this flag is set, the login lineedit will be in read only mode. */ UsernameReadOnly = 0x04, /** * If this flag is set, the Anonymous Login checkbox will be displayed * @since 4.1 */ ShowAnonymousLoginCheckBox = 0x08, /** * If this flag is set, there will be an additional line to let the user enter the domain. * @since 4.1 */ ShowDomainLine = 0x10, /** * If this flag is set, the domain lineedit will be in read only mode. * @since 4.1 */ DomainReadOnly = 0x20 }; Q_DECLARE_FLAGS(KPasswordDialogFlags, KPasswordDialogFlag) enum ErrorType { UnknownError = 0, /** * A problem with the user name as entered **/ UsernameError, /** * Incorrect password */ PasswordError, /** * Error preventing further attempts, will result in disabling most of the interface */ FatalError, /** * A problem with the domain as entered * @since 4.1 **/ DomainError }; /** * create a password dialog * * @param parent the parent widget * @param flags a set of KPasswordDialogFlag flags */ explicit KPasswordDialog(QWidget *parent = nullptr, - const KPasswordDialogFlags &flags = nullptr); + const KPasswordDialogFlags &flags = KPasswordDialog::NoFlags); /** * Destructor */ ~KPasswordDialog(); /** * Sets the prompt to show to the user. * @param prompt instructional text to be shown. */ void setPrompt(const QString &prompt); /** * Returns the prompt */ QString prompt() const; /** * set an image that appears next to the prompt. */ void setPixmap(const QPixmap &); /** * */ QPixmap pixmap() const; /** * Adds a comment line to the dialog. * * This function allows you to add one additional comment * line to this widget. Calling this function after a * comment has already been added will not have any effect. * * @param label label for comment (ex:"Command:") * @param comment the actual comment text. */ void addCommentLine(const QString &label, const QString &comment); /** * Shows an error message in the dialog box. Prevents having to show a dialog-on-a-dialog. * * @param message the error message to show */ void showErrorMessage(const QString &message, const ErrorType type = PasswordError); /** * Returns the password entered by the user. * @return the password */ QString password() const; /** * set the default username. */ void setUsername(const QString &); /** * Returns the username entered by the user. * @return the user name */ QString username() const; /** * set the default domain. * @since 4.1 */ void setDomain(const QString &); /** * Returns the domain entered by the user. * @return the domain name * @since 4.1 */ QString domain() const; /** * set anonymous mode (all other fields will be grayed out) * @since 4.1 */ void setAnonymousMode(bool anonymous); /** * @return anonymous mode has been selected. * @since 4.1 */ bool anonymousMode() const; /** * Determines whether supplied authorization should * persist even after the application has been closed. * * this is set with the check password checkbox is the ShowKeepCheckBox flag * is set in the constructor, if it is not set, this function return false * * @return true to keep the password */ bool keepPassword() const; /** * Check or uncheck the "keep password" checkbox. * This can be used to check it before showing the dialog, to tell * the user that the password is stored already (e.g. in the wallet). * enableKeep must have been set to true in the constructor. * * has only effect if ShowKeepCheckBox is set in the constructor */ void setKeepPassword(bool b); /** * Sets the username field read-only and sets the * focus to the password field. * * this can also be set by passing UsernameReadOnly as flag in the constructor * * @param readOnly true to set the user field to read-only */ void setUsernameReadOnly(bool readOnly); /** * Presets the password. * If the password is not empty, the ability to show the password will not be available. * @param password the password to set */ void setPassword(const QString &password); /** * Presets a number of login+password pairs that the user can choose from. * The passwords can be empty if you simply want to offer usernames to choose from. * * This require the flag ShowUnernameLine to be set in the constructoe, and not the flag UsernameReadOnly * @param knownLogins map of known logins: the keys are usernames, the values are passwords. */ void setKnownLogins(const QMap &knownLogins); /** * @internal */ void accept() Q_DECL_OVERRIDE; /** * Returns the button box used in the dialog. * This can be used to add new buttons. * * @return the button box * * @since 5.0 */ QDialogButtonBox *buttonBox() const; Q_SIGNALS: /** * emitted when the dialog has been accepted * @param password the entered password * @param keep true if the "remember password" checkbox was checked, false otherwise. false if ShowKeepPassword was not set in the constructor */ void gotPassword(const QString &password, bool keep); /** * emitted when the dialog has been accepted, and ShowUsernameLine was set on the constructor * @param username the entered username * @param password the entered password * @param keep true if the "remember password" checkbox was checked, false otherwise. false if ShowKeepPassword was not set in the constructor */ void gotUsernameAndPassword(const QString &username, const QString &password, bool keep); protected: /** * Virtual function that can be overridden to provide password * checking in derived classes. It should return @p true if the * password is valid, @p false otherwise. */ virtual bool checkPassword(); private: Q_PRIVATE_SLOT(d, void actuallyAccept()) Q_PRIVATE_SLOT(d, void activated(const QString &userName)) Q_PRIVATE_SLOT(d, void updateFields()) Q_PRIVATE_SLOT(d, void toggleEchoMode()) Q_PRIVATE_SLOT(d, void showToggleEchoModeAction(const QString &text)) private: class KPasswordDialogPrivate; friend class KPasswordDialogPrivate; KPasswordDialogPrivate *const d; Q_DISABLE_COPY(KPasswordDialog) }; Q_DECLARE_OPERATORS_FOR_FLAGS(KPasswordDialog::KPasswordDialogFlags) #endif diff --git a/src/kruler.h b/src/kruler.h index febef5c..9489255 100644 --- a/src/kruler.h +++ b/src/kruler.h @@ -1,386 +1,386 @@ /* -*- c++ -*- */ /* This file is part of the KDE libraries Copyright (C) 1998 Jörg Habenicht (j.habenicht@europemail.com) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KRULER_H #define KRULER_H #include #include /** * @class KRuler kruler.h KRuler * * A ruler widget. * * The vertical ruler looks similar to this: * *\code * meters inches * * ------ <--- end mark ---> ------ * -- - * -- <---little mark---> -- * -- - * -- --- * --- <---medium mark - * -- -- * -- tiny mark----> - * -- ---- * -- - * ---- <-----big mark -- * -- - * |>-- <--ruler pointer--> |>-- * * \endcode * * There are tiny marks, little marks, medium marks, and big marks along the * ruler. * * To receive mouse clicks or mouse moves, the class has to be overloaded. * * \image html kruler.png "KRuler Widget" * * @short A ruler widget. * @author Jörg Habenicht */ class KWIDGETSADDONS_EXPORT KRuler : public QAbstractSlider { Q_OBJECT Q_PROPERTY(bool showTinyMarks READ showTinyMarks WRITE setShowTinyMarks) Q_PROPERTY(bool showLittleMarks READ showLittleMarks WRITE setShowLittleMarks) Q_PROPERTY(bool showMediumMarks READ showMediumMarks WRITE setShowMediumMarks) Q_PROPERTY(bool showBigMarks READ showBigMarks WRITE setShowBigMarks) Q_PROPERTY(bool showPointer READ showPointer WRITE setShowPointer) Q_PROPERTY(bool showEndLabel READ showEndLabel WRITE setShowEndLabel) Q_PROPERTY(int tinyMarkDistance READ tinyMarkDistance WRITE setTinyMarkDistance) Q_PROPERTY(int littleMarkDistance READ littleMarkDistance WRITE setLittleMarkDistance) Q_PROPERTY(int mediumMarkDistance READ mediumMarkDistance WRITE setBigMarkDistance) Q_PROPERTY(int bigMarkDistance READ bigMarkDistance WRITE setBigMarkDistance) Q_PROPERTY(double pixelPerMark READ pixelPerMark WRITE setPixelPerMark) Q_PROPERTY(bool lengthFixed READ lengthFixed WRITE setLengthFixed) Q_PROPERTY(QString endLabel READ endLabel WRITE setEndLabel) Q_PROPERTY(int length READ length WRITE setLength) Q_PROPERTY(int offset READ offset) Q_PROPERTY(int endOffset READ endOffset) public: /** * The types of units used. **/ enum MetricStyle { Custom = 0, Pixel, Inch, Millimetres, Centimetres, Metres }; Q_ENUM(MetricStyle) /** * Constructs a horizontal ruler. */ explicit KRuler(QWidget *parent = nullptr); /** * Constructs a ruler with orientation @p orient. * * @p parent and @p f are passed to QFrame. * The default look is a raised widget * but may be changed with the inherited QFrame methods. * * @param orient Orientation of the ruler. * @param parent Will be handed over to QFrame. * @param f Will be handed over to QFrame. * **/ - explicit KRuler(Qt::Orientation orient, QWidget *parent = nullptr, Qt::WindowFlags f = nullptr); + explicit KRuler(Qt::Orientation orient, QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); /** * Constructs a ruler with orientation @p orient and initial width @p widgetWidth. * * The width sets the fixed width of the widget. This is useful if you * want to draw the ruler bigger or smaller than the default size. * Note: The size of the marks doesn't change. * @p parent and @p f are passed to QFrame. * * @param orient Orientation of the ruler. * @param widgetWidth Fixed width of the widget. * @param parent Will be handed over to QFrame. * @param f Will be handed over to QFrame. * */ KRuler(Qt::Orientation orient, int widgetWidth, QWidget *parent = nullptr, - Qt::WindowFlags f = nullptr); + Qt::WindowFlags f = Qt::WindowFlags()); /** * Destructor. */ ~KRuler(); /** * Sets the minimal value of the ruler pointer (default is 0). * * This method calls update() so that the widget is painted after leaving * to the main event loop. * **/ #ifndef KWIDGETSADDONS_NO_DEPRECATED KWIDGETSADDONS_DEPRECATED void setMinValue(int); #endif /** * Returns the minimal value of the ruler pointer. **/ #ifndef KWIDGETSADDONS_NO_DEPRECATED KWIDGETSADDONS_DEPRECATED int minValue() const; #endif /** * Sets the maximum value of the ruler pointer (default is 100). * * This method calls update() so that the widget is painted after leaving * to the main event loop. */ #ifndef KWIDGETSADDONS_NO_DEPRECATED KWIDGETSADDONS_DEPRECATED void setMaxValue(int); #endif /** * Returns the maximal value of the ruler pointer. */ #ifndef KWIDGETSADDONS_NO_DEPRECATED KWIDGETSADDONS_DEPRECATED int maxValue() const; #endif /** * Sets the distance between tiny marks. * * This is mostly used in the English system (inches) with distance of 1. */ void setTinyMarkDistance(int); /** * Returns the distance between tiny marks. **/ int tinyMarkDistance() const; /** * Sets the distance between little marks. * * The default value is 1 in the metric system and 2 in the English (inches) system. */ void setLittleMarkDistance(int); /** * Returns the distance between little marks. */ int littleMarkDistance() const; /** * Sets the distance between medium marks. * * For English (inches) styles it defaults to twice the little mark distance. * For metric styles it defaults to five times the little mark distance. **/ void setMediumMarkDistance(int); int mediumMarkDistance() const; /** * Sets distance between big marks. * * For English (inches) or metric styles it is twice the medium mark distance. **/ void setBigMarkDistance(int); /** * Returns the distance between big marks. **/ int bigMarkDistance() const; /** * Shows/hides tiny marks. **/ void setShowTinyMarks(bool); bool showTinyMarks() const; /** * Shows/hides little marks. **/ void setShowLittleMarks(bool); bool showLittleMarks() const; /** * Shows/hides medium marks. **/ void setShowMediumMarks(bool); bool showMediumMarks() const; /** * Shows/hides big marks. **/ void setShowBigMarks(bool); bool showBigMarks() const; /** * Shows/hides end marks. **/ void setShowEndMarks(bool); bool showEndMarks() const; /** * Shows/hides the pointer. */ void setShowPointer(bool); bool showPointer() const; #ifndef KWIDGETSADDONS_NO_DEPRECATED KWIDGETSADDONS_DEPRECATED void setFrameStyle(int); #endif /** * Show/hide number values of the end marks. * * Default is @p false. **/ void setShowEndLabel(bool); bool showEndLabel() const; /** * Sets the label this is drawn at the beginning of the visible part * of the ruler to @p label **/ void setEndLabel(const QString &); QString endLabel() const; /** * Sets up the necessary tasks for the provided styles. * * A convenience method. **/ void setRulerMetricStyle(KRuler::MetricStyle); /** * Sets the number of pixels between two base marks. * * Calling this method stretches or shrinks your ruler. * * For pixel display ( MetricStyle) the value is 10.0 marks * per pixel ;-) * For English (inches) it is 9.0, and for centimetres ~2.835 -> 3.0 . * If you want to magnify your part of display, you have to * adjust the mark distance @p here. * Notice: The double type is only supported to give the possibility * of having some double values. * It should be used with care. Using values below 10.0 * shows visible jumps of markpositions (e.g. 2.345). * Using whole numbers is highly recommended. * To use @p int values use setPixelPerMark((int)your_int_value); * default: 1 mark per 10 pixels */ void setPixelPerMark(double rate); /** * Returns the number of pixels between two base marks. **/ double pixelPerMark() const; /** * Sets the length of the ruler, i.e. the difference between * the begin mark and the end mark of the ruler. * * Same as (width() - offset()) * * when the length is not locked, it gets adjusted with the * length of the widget. */ void setLength(int); int length() const; /** * Locks the length of the ruler, i.e. the difference between * the two end marks doesn't change when the widget is resized. * * @param fix fixes the length, if true */ void setLengthFixed(bool fix); bool lengthFixed() const; /** * Sets the number of pixels by which the ruler may slide up or left. * The number of pixels moved is realive to the previous position. * The Method makes sense for updating a ruler, which is working with * a scrollbar. * * This doesn't affect the position of the ruler pointer. * Only the visible part of the ruler is moved. * * @param count Number of pixel moving up or left relative to the previous position **/ void slideUp(int count = 1); /** * Sets the number of pixels by which the ruler may slide down or right. * The number of pixels moved is realive to the previous position. * The Method makes sense for updating a ruler, which is working with * a scrollbar. * * This doesn't affect the position of the ruler pointer. * Only the visible part of the ruler is moved. * * @param count Number of pixel moving up or left relative to the previous position **/ void slideDown(int count = 1); /** * Sets the ruler slide offset. * * This is like slideup() or slidedown() with an absolute offset * from the start of the ruler. * * @param offset Number of pixel to move the ruler up or left from the beginning **/ void setOffset(int offset); /** * Returns the current ruler offset. **/ int offset() const; int endOffset() const; public Q_SLOTS: /** * Sets the pointer to a new position. * * The offset is NOT updated. * QWidget::repaint() is called afterwards. **/ void slotNewValue(int); /** * Sets the ruler marks to a new position. * * The pointer is NOT updated. * QWidget::repaint() is called afterwards. **/ void slotNewOffset(int); void slotEndOffset(int); protected: void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE; private: void initWidget(Qt::Orientation orientation); private: class KRulerPrivate; KRulerPrivate *const d; }; #endif diff --git a/src/kseparator.h b/src/kseparator.h index cba883d..5b7b107 100644 --- a/src/kseparator.h +++ b/src/kseparator.h @@ -1,75 +1,75 @@ /* * Copyright (C) 1997 Michael Roth * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * */ #ifndef KSEPARATOR_H #define KSEPARATOR_H #include #include /** * @class KSeparator kseparator.h KSeparator * * Standard horizontal or vertical separator. * * \image html kseparator-horizontal.png "KSeparator Widget with horizontal orientation" * \image html kseparator-vertical.png "KSeparator Widget with vertical orientation" * * @author Michael Roth */ class KWIDGETSADDONS_EXPORT KSeparator : public QFrame { Q_OBJECT Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation) public: /** * Constructor. * @param parent parent object. * @param f extra QWidget flags. **/ - explicit KSeparator(QWidget *parent = nullptr, Qt::WindowFlags f = nullptr); + explicit KSeparator(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); /** * Constructor. * @param orientation Set the orientation of the separator. * Possible values are Horizontal or Vertical. * @param parent parent object. * @param f extra QWidget flags. **/ - explicit KSeparator(Qt::Orientation orientation, QWidget *parent = nullptr, Qt::WindowFlags f = nullptr); + explicit KSeparator(Qt::Orientation orientation, QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); /** * Returns the orientation of the separator. * @return int Possible values Horizontal or Vertical. **/ Qt::Orientation orientation() const; /** * Set the orientation of the separator to @p orientation * * @param orientation Possible values are Vertical and Horizontal. */ void setOrientation(Qt::Orientation orientation); private: class KSeparatorPrivate *d; }; #endif // KSEPARATOR_H