introduce kmessagewidget in settings window

--use the nicely look kmessagewidget in order to
show inline internal messages to the user
pull/11/head
Michail Vourlakos 5 years ago
parent 300f4a364f
commit 3e3b455a53

@ -21,6 +21,7 @@
#include "layoutscontroller.h" #include "layoutscontroller.h"
// local // local
#include "../settingsdialog.h"
#include "../universalsettings.h" #include "../universalsettings.h"
#include "../delegates/activitiesdelegate.h" #include "../delegates/activitiesdelegate.h"
#include "../delegates/backgroundcmbdelegate.h" #include "../delegates/backgroundcmbdelegate.h"
@ -49,6 +50,7 @@
#include <KArchive/KTar> #include <KArchive/KTar>
#include <KArchive/KArchiveEntry> #include <KArchive/KArchiveEntry>
#include <KArchive/KArchiveDirectory> #include <KArchive/KArchiveDirectory>
#include <KMessageWidget>
#include <KNotification> #include <KNotification>
@ -56,7 +58,7 @@ namespace Latte {
namespace Settings { namespace Settings {
namespace Controller { namespace Controller {
Layouts::Layouts(QDialog *parent, Latte::Corona *corona, QTableView *view) Layouts::Layouts(Latte::SettingsDialog *parent, Latte::Corona *corona, QTableView *view)
: QObject(parent), : QObject(parent),
m_parentDialog(parent), m_parentDialog(parent),
m_corona(corona), m_corona(corona),
@ -847,7 +849,7 @@ void Layouts::saveColumnWidths()
void Layouts::on_nameDuplicatedFrom(const QString &provenId, const QString &trialId) void Layouts::on_nameDuplicatedFrom(const QString &provenId, const QString &trialId)
{ {
//! duplicated layout name //! duplicated layout name
auto msg = new QMessageBox(m_parentDialog); /*auto msg = new QMessageBox(m_parentDialog);
msg->setIcon(QMessageBox::Warning); msg->setIcon(QMessageBox::Warning);
msg->setWindowTitle(i18n("Layout Warning")); msg->setWindowTitle(i18n("Layout Warning"));
msg->setText(i18n("There are layouts with the same name, that is not permitted!!! Please update these names to re-apply the changes...")); msg->setText(i18n("There are layouts with the same name, that is not permitted!!! Please update these names to re-apply the changes..."));
@ -874,7 +876,33 @@ void Layouts::on_nameDuplicatedFrom(const QString &provenId, const QString &tria
}); });
msg->open(); msg->open();*/
int pRow = rowForId(provenId);
int tRow = rowForId(trialId);
if (pRow >= 0) {
QItemSelectionModel::SelectionFlags flags = QItemSelectionModel::ClearAndSelect;
QItemSelection rowSelection;
QModelIndex pIndexS = m_proxyModel->index(pRow, Model::Layouts::BACKGROUNDCOLUMN);
QModelIndex pIndexE = m_proxyModel->index(pRow, Model::Layouts::SHAREDCOLUMN);
rowSelection.select(pIndexS, pIndexE);
m_view->selectionModel()->select(rowSelection, flags);
}
m_parentDialog->showInlineMessage(i18n("Layouts with same name are not permitted! Please provide unique names to proceed..."), KMessageWidget::Error, 4000);
QModelIndex tIndex = m_proxyModel->index(tRow, Model::Layouts::NAMECOLUMN);
//! avoid losing focuse
QTimer::singleShot(0, [this, tIndex]() {
m_view->edit(tIndex);
});
} }
} }

@ -38,6 +38,7 @@
namespace Latte { namespace Latte {
class Corona; class Corona;
class CentralLayout; class CentralLayout;
class SettingsDialog;
} }
namespace Latte { namespace Latte {
@ -49,7 +50,7 @@ class Layouts : public QObject
Q_OBJECT Q_OBJECT
public: public:
explicit Layouts(QDialog *parent, Latte::Corona *corona, QTableView *view); explicit Layouts(Latte::SettingsDialog *parent, Latte::Corona *corona, QTableView *view);
~Layouts(); ~Layouts();
QAbstractItemModel *model() const; QAbstractItemModel *model() const;
@ -100,7 +101,7 @@ private:
QString uniqueLayoutName(QString name); QString uniqueLayoutName(QString name);
private: private:
QDialog *m_parentDialog{nullptr}; Latte::SettingsDialog *m_parentDialog{nullptr};
Latte::Corona *m_corona{nullptr}; Latte::Corona *m_corona{nullptr};
QTableView *m_view{nullptr}; QTableView *m_view{nullptr};
Settings::Layouts::HeaderView *m_headerView{nullptr}; Settings::Layouts::HeaderView *m_headerView{nullptr};

@ -95,6 +95,7 @@ SettingsDialog::SettingsDialog(QWidget *parent, Latte::Corona *corona)
ui->screenTrackerSpinBox->setValue(m_corona->universalSettings()->screenTrackerInterval()); ui->screenTrackerSpinBox->setValue(m_corona->universalSettings()->screenTrackerInterval());
ui->outlineSpinBox->setValue(m_corona->themeExtended()->outlineWidth()); ui->outlineSpinBox->setValue(m_corona->themeExtended()->outlineWidth());
ui->messageWidget->setVisible(false);
//! About Menu //! About Menu
QMenuBar *menuBar = new QMenuBar(this); QMenuBar *menuBar = new QMenuBar(this);
@ -216,6 +217,12 @@ SettingsDialog::SettingsDialog(QWidget *parent, Latte::Corona *corona)
m_activitiesTimer.setInterval(750); m_activitiesTimer.setInterval(750);
connect(&m_activitiesTimer, &QTimer::timeout, this, &SettingsDialog::updateWindowActivities); connect(&m_activitiesTimer, &QTimer::timeout, this, &SettingsDialog::updateWindowActivities);
m_activitiesTimer.start(); m_activitiesTimer.start();
m_hideInlineMessageTimer.setSingleShot(true);
m_hideInlineMessageTimer.setInterval(2000);
connect(&m_hideInlineMessageTimer, &QTimer::timeout, this, [&]() {
ui->messageWidget->animatedHide();
});
} }
SettingsDialog::~SettingsDialog() SettingsDialog::~SettingsDialog()
@ -638,6 +645,13 @@ void SettingsDialog::on_switchButton_clicked()
{ {
Settings::Data::Layout selectedLayout = m_layoutsController->selectedLayout(); Settings::Data::Layout selectedLayout = m_layoutsController->selectedLayout();
bool hasChanges = (selectedLayout.nameWasEdited() || m_layoutsController->dataAreChanged());
if (hasChanges) {
showInlineMessage(i18n("You need to save your changes before switching to other layout."), KMessageWidget::Warning);
return;
}
if (!m_layoutsController->selectedLayoutIsCurrentActive()) { if (!m_layoutsController->selectedLayoutIsCurrentActive()) {
bool appliedShared = m_layoutsController->inMultipleMode() && selectedLayout.isShared(); bool appliedShared = m_layoutsController->inMultipleMode() && selectedLayout.isShared();
bool freeActivitiesLayoutUpdated{false}; bool freeActivitiesLayoutUpdated{false};
@ -726,9 +740,7 @@ void SettingsDialog::updatePerLayoutButtonsState()
Settings::Data::Layout selectedLayout = m_layoutsController->selectedLayout(); Settings::Data::Layout selectedLayout = m_layoutsController->selectedLayout();
//! Switch Button //! Switch Button
if (selectedLayout.nameWasEdited() if ((m_layoutsController->inMultipleMode() && selectedLayout.isShared())
|| m_layoutsController->dataAreChanged()
|| (m_layoutsController->inMultipleMode() && selectedLayout.isShared())
|| m_layoutsController->selectedLayoutIsCurrentActive()) { || m_layoutsController->selectedLayoutIsCurrentActive()) {
ui->switchButton->setEnabled(false); ui->switchButton->setEnabled(false);
} else { } else {
@ -857,5 +869,36 @@ void SettingsDialog::saveAllChanges()
m_layoutsController->save(); m_layoutsController->save();
} }
void SettingsDialog::showInlineMessage(const QString &msg, const KMessageWidget::MessageType &type, const int &hideInterval)
{
if (msg.isEmpty()) {
return;
}
m_hideInlineMessageTimer.stop();
if (ui->messageWidget->isVisible()) {
ui->messageWidget->animatedHide();
}
ui->messageWidget->setText(msg);
// TODO: wrap at arbitrary character positions once QLabel can do this
// https://bugreports.qt.io/browse/QTBUG-1276
ui->messageWidget->setWordWrap(true);
ui->messageWidget->setMessageType(type);
ui->messageWidget->setWordWrap(false);
const int unwrappedWidth = ui->messageWidget->sizeHint().width();
ui->messageWidget->setWordWrap(unwrappedWidth > size().width());
ui->messageWidget->animatedShow();
if (hideInterval > 0) {
m_hideInlineMessageTimer.setInterval(hideInterval);
m_hideInlineMessageTimer.start();
}
}
}//end of namespace }//end of namespace

@ -36,6 +36,7 @@
// KDE // KDE
#include <KHelpMenu> #include <KHelpMenu>
#include <KMessageWidget>
namespace Ui { namespace Ui {
class SettingsDialog; class SettingsDialog;
@ -65,6 +66,8 @@ public:
void requestImagesDialog(int row); void requestImagesDialog(int row);
void requestColorsDialog(int row); void requestColorsDialog(int row);
void showInlineMessage(const QString &msg, const KMessageWidget::MessageType &type, const int &hideInterval = 0);
private slots: private slots:
// auto connections // auto connections
void on_newButton_clicked(); void on_newButton_clicked();
@ -111,6 +114,8 @@ private:
//! workaround to assign ALLACTIVITIES during startup //! workaround to assign ALLACTIVITIES during startup
QTimer m_activitiesTimer; QTimer m_activitiesTimer;
//! Timer to hide the inline message widget
QTimer m_hideInlineMessageTimer;
//! original data //! original data
QList<int> o_settingsOriginalData; QList<int> o_settingsOriginalData;

@ -1185,6 +1185,9 @@ This tracker is used in order to not lose any screen related update.</string>
</widget> </widget>
</widget> </widget>
</item> </item>
<item>
<widget class="KMessageWidget" name="messageWidget"/>
</item>
<item> <item>
<widget class="QDialogButtonBox" name="buttonBox"> <widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation"> <property name="orientation">
@ -1197,6 +1200,13 @@ This tracker is used in order to not lose any screen related update.</string>
</item> </item>
</layout> </layout>
</widget> </widget>
<customwidgets>
<customwidget>
<class>KMessageWidget</class>
<extends>QFrame</extends>
<header>kmessagewidget.h</header>
</customwidget>
</customwidgets>
<resources/> <resources/>
<connections> <connections>
<connection> <connection>

Loading…
Cancel
Save