File indexing completed on 2024-04-28 15:14:00
0001 /*************************************************************************** 0002 File : HistoryDialog.cpp 0003 Project : LabPlot 0004 Description : history dialog 0005 -------------------------------------------------------------------- 0006 Copyright : (C) 2012-2019 by Alexander Semke (alexander.semke@web.de) 0007 0008 ***************************************************************************/ 0009 0010 /*************************************************************************** 0011 * * 0012 * This program is free software; you can redistribute it and/or modify * 0013 * it under the terms of the GNU General Public License as published by * 0014 * the Free Software Foundation; either version 2 of the License, or * 0015 * (at your option) any later version. * 0016 * * 0017 * This program is distributed in the hope that it will be useful, * 0018 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0020 * GNU General Public License for more details. * 0021 * * 0022 * You should have received a copy of the GNU General Public License * 0023 * along with this program; if not, write to the Free Software * 0024 * Foundation, Inc., 51 Franklin Street, Fifth Floor, * 0025 * Boston, MA 02110-1301 USA * 0026 * * 0027 ***************************************************************************/ 0028 #include "HistoryDialog.h" 0029 0030 #include <QDialogButtonBox> 0031 #include <QPushButton> 0032 #include <QVBoxLayout> 0033 #include <QWindow> 0034 #include <QUndoStack> 0035 #include <QUndoView> 0036 0037 #include <KMessageBox> 0038 #include <KLocalizedString> 0039 #include <KSharedConfig> 0040 #include <KWindowConfig> 0041 0042 /*! 0043 \class HistoryDialog 0044 \brief Display the content of project's undo stack. 0045 0046 \ingroup kdefrontend 0047 */ 0048 HistoryDialog::HistoryDialog(QWidget* parent, QUndoStack* stack, const QString& emptyLabel) : QDialog(parent), 0049 m_undoStack(stack) { 0050 auto* undoView = new QUndoView(stack, this); 0051 undoView->setCleanIcon( QIcon::fromTheme("edit-clear-history") ); 0052 undoView->setEmptyLabel(emptyLabel); 0053 undoView->setMinimumWidth(350); 0054 undoView->setWhatsThis(i18n("List of all performed steps/actions.\n" 0055 "Select an item in the list to navigate to the corresponding step.")); 0056 0057 setWindowIcon( QIcon::fromTheme("view-history") ); 0058 setWindowTitle(i18nc("@title:window", "Undo/Redo History")); 0059 setAttribute(Qt::WA_DeleteOnClose); 0060 auto* btnBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); 0061 m_okButton = btnBox->button(QDialogButtonBox::Ok); 0062 0063 connect(btnBox->button(QDialogButtonBox::Cancel), &QPushButton::clicked, this, &HistoryDialog::close); 0064 connect(btnBox, &QDialogButtonBox::accepted, this, &HistoryDialog::accept); 0065 connect(btnBox, &QDialogButtonBox::rejected, this, &HistoryDialog::reject); 0066 0067 if (stack->count()) { 0068 m_clearUndoStackButton = new QPushButton; 0069 btnBox->addButton(m_clearUndoStackButton, QDialogButtonBox::ActionRole); 0070 m_clearUndoStackButton->setText(i18n("&Clear")); 0071 m_clearUndoStackButton->setToolTip(i18n("Clears the undo history. Commands are not undone or redone; the state of the project remains unchanged.")); 0072 m_clearUndoStackButton->setIcon(QIcon::fromTheme("edit-clear")); 0073 connect(m_clearUndoStackButton, &QPushButton::clicked, this, &HistoryDialog::clearUndoStack); 0074 } 0075 0076 QFrame* line = new QFrame; 0077 line->setFrameShape(QFrame::HLine); 0078 line->setFrameShadow(QFrame::Sunken); 0079 0080 auto* layout = new QVBoxLayout; 0081 0082 layout->addWidget(undoView); 0083 layout->addWidget(line); 0084 layout->addWidget(btnBox); 0085 0086 setLayout(layout); 0087 0088 //restore saved settings if available 0089 create(); // ensure there's a window created 0090 KConfigGroup conf(KSharedConfig::openConfig(), "HistoryDialog"); 0091 if (conf.exists()) { 0092 KWindowConfig::restoreWindowSize(windowHandle(), conf); 0093 resize(windowHandle()->size()); // workaround for QTBUG-40584 0094 } else 0095 resize(QSize(500, 300).expandedTo(minimumSize())); 0096 } 0097 0098 HistoryDialog::~HistoryDialog() { 0099 //save dialog size 0100 KConfigGroup conf(KSharedConfig::openConfig(), "HistoryDialog"); 0101 KWindowConfig::saveWindowSize(windowHandle(), conf); 0102 } 0103 0104 void HistoryDialog::clearUndoStack() { 0105 if (KMessageBox::questionYesNo( this, 0106 i18n("Do you really want to clear the undo history?"), 0107 i18n("Clear History") 0108 ) == KMessageBox::Yes) 0109 m_undoStack->clear(); 0110 }