From: hama Date: Tue, 19 May 2015 22:05:48 +0000 (+0200) Subject: ReFinder: fix delete problem in option dialog X-Git-Url: https://gitweb.hamatoma.de/?a=commitdiff_plain;h=ade3c1adb1dfee34321a2cca3a1014147e0c5af4;p=reqt ReFinder: fix delete problem in option dialog * ReFinder: handling of up-down keys in option dialog * ReFind: improvements * ReViewer: base classes --- diff --git a/appl/refind/dialogoptions.cpp b/appl/refind/dialogoptions.cpp index 75bfb19..358cc3d 100644 --- a/appl/refind/dialogoptions.cpp +++ b/appl/refind/dialogoptions.cpp @@ -11,7 +11,39 @@ #include "ui_dialogoptions.h" #include "math.h" #include +#include +#include +/** + * Constructor. + * + * @param dialog the option dialog + */ +TableKeyPressEater::TableKeyPressEater(DialogOptions* dialog) : + QObject(dialog), + m_dialog(dialog) +{ +} + + +/** + * Event handler for the up/down keys of the table widget. + * + * @param obj the table widget + * @param event the current event + * @return + */ +bool TableKeyPressEater::eventFilter(QObject *obj, QEvent *event) +{ + if (event->type() == QEvent::KeyPress){ + QKeyEvent *keyEvent = static_cast(event); + int key = keyEvent->key(); + if (key == Qt::Key_Up || key == Qt::Key_Down) + m_dialog->handleKey(key); + } + // standard event processing + return QObject::eventFilter(obj, event); +} /** * Constructor. * @@ -33,6 +65,9 @@ DialogOptions::DialogOptions(ContextHandlerList& handlers, QWidget *parent) : connect(ui->pushButtonUp, SIGNAL(clicked()), this, SLOT(up())); connect(ui->tableWidget, SIGNAL(cellClicked(int,int)), this, SLOT(cellEntered(int,int))); connect(ui->tableWidget, SIGNAL(selectionChanged()), this, SLOT(selectionChanged())); + connect(ui->tableWidget, SIGNAL(currentItemChanged()), this, SLOT(currentItemChanged())); + ui->tableWidget->installEventFilter(new TableKeyPressEater(this)); + for (int ix = 0; ix < ui->comboBoxFileType->count(); ix++) m_fileTypes.append(ui->comboBoxFileType->itemText(ix)); for (int ix = 0; ix < ui->comboBoxDirMode->count(); ix++) @@ -48,6 +83,11 @@ DialogOptions::~DialogOptions(){ delete ui; } +void DialogOptions::currentItemChanged(QTableWidgetItem * current, + QTableWidgetItem * previous){ + QString text = current->text() + " " + previous->text(); +} + /** * Handles the event "pushed button add". */ @@ -118,10 +158,7 @@ void DialogOptions::currentToTable(int row){ */ void DialogOptions::del(){ int count = ui->tableWidget->rowCount() - 1; - int start = m_selectedRow; - if (start == 0) - start = 1; - for (int row = start; row < count; row++){ + for (int row = m_selectedRow + 1; row <= count; row++){ swapRows(row, row - 1); } ui->tableWidget->setRowCount(count); @@ -191,6 +228,22 @@ void DialogOptions::fromTable(){ } } +/** + * Handles the up/down key press event. + * + * @param key the key (up or down) + */ +void DialogOptions::handleKey(int key) +{ + if (key == Qt::Key_Down){ + if (m_selectedRow < ui->tableWidget->rowCount() - 1) + m_selectedRow++; + } else if (key == Qt::Key_Up){ + if (m_selectedRow > 0) + m_selectedRow--; + } +} + /** * Deselects the current row and selects another. * @param row the number of the new selected row diff --git a/appl/refind/dialogoptions.hpp b/appl/refind/dialogoptions.hpp index da9d9ec..5f15e91 100644 --- a/appl/refind/dialogoptions.hpp +++ b/appl/refind/dialogoptions.hpp @@ -15,6 +15,18 @@ namespace Ui { class DialogOptions; } +class DialogOptions; +class TableKeyPressEater : public QObject +{ + Q_OBJECT +public: + TableKeyPressEater(DialogOptions* dialog); +protected: + bool eventFilter(QObject *obj, QEvent *event); +private: + DialogOptions* m_dialog; +}; + class DialogOptions: public QDialog { Q_OBJECT @@ -30,8 +42,11 @@ private slots: void selectProgram(); void selectionChanged(); void up(); +public: + void handleKey(int key); private: void currentToTable(int row); + void currentItemChanged(QTableWidgetItem* current, QTableWidgetItem* previous); void fillContextHandler(int row, ContextHandler& handler); void fillTable(); void fromTable(); diff --git a/appl/refind/mainwindow.cpp b/appl/refind/mainwindow.cpp index f2011d9..170fd21 100644 --- a/appl/refind/mainwindow.cpp +++ b/appl/refind/mainwindow.cpp @@ -45,7 +45,7 @@ MainWindow::MainWindow(const QString& startDir, const QString& homeDir, m_lastBaseDir(), m_horizontalHeader(NULL), m_lastOrder(Qt::DescendingOrder), - m_homeDir(), + m_homeDir(homeDir), m_storageFile(), m_contextHandlers(){ ui->setupUi(this); diff --git a/appl/reviewer/about.ui b/appl/reviewer/about.ui new file mode 100644 index 0000000..a6d80c5 --- /dev/null +++ b/appl/reviewer/about.ui @@ -0,0 +1,74 @@ + + + AboutDialog + + + + 0 + 0 + 400 + 225 + + + + About + + + + + 20 + 20 + 351 + 141 + + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">ReFind</span> for searching files in a directory tree</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">This is a program of the project &quot;<span style=" font-weight:600;">Re</span>al <span style=" font-weight:600;">Pub</span>lic <span style=" font-weight:600;">Lib</span>rary&quot;.</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Sources are public domain and available under https://github.com/republib</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Implemented in QT (C++) 5.x</p></body></html> + + + + + + 280 + 180 + 93 + 27 + + + + &OK + + + + + &OK + + + + + + + action_OK + triggered() + AboutDialog + close() + + + -1 + -1 + + + 199 + 112 + + + + + diff --git a/appl/reviewer/aboutdialog.cpp b/appl/reviewer/aboutdialog.cpp new file mode 100644 index 0000000..43a6eb5 --- /dev/null +++ b/appl/reviewer/aboutdialog.cpp @@ -0,0 +1,19 @@ +/* + * Licence: + * You can use and modify this file without any restriction. + * There is no warranty. + * You also can use the licence from http://www.wtfpl.net/. + * The original sources can be found on https://github.com/republib. + */ + +#include "aboutdialog.hpp" +#include "ui_aboutdialog.h" + +AboutDialog::AboutDialog(QWidget *parent) : + QDialog(parent), ui(new Ui::AboutDialog){ + ui->setupUi(this); +} + +AboutDialog::~AboutDialog(){ + delete ui; +} diff --git a/appl/reviewer/aboutdialog.hpp b/appl/reviewer/aboutdialog.hpp new file mode 100644 index 0000000..b15b499 --- /dev/null +++ b/appl/reviewer/aboutdialog.hpp @@ -0,0 +1,29 @@ +/* + * Licence: + * You can use and modify this file without any restriction. + * There is no warranty. + * You also can use the licence from http://www.wtfpl.net/. + * The original sources can be found on https://github.com/republib. + */ + +#ifndef ABOUTDIALOG_HPP +#define ABOUTDIALOG_HPP + +#include + +namespace Ui { +class AboutDialog; +} + +class AboutDialog: public QDialog { + Q_OBJECT + +public: + explicit AboutDialog(QWidget *parent = 0); + ~AboutDialog(); + +private: + Ui::AboutDialog *ui; +}; + +#endif // ABOUTDIALOG_HPP diff --git a/appl/reviewer/aboutdialog.ui b/appl/reviewer/aboutdialog.ui new file mode 100644 index 0000000..b5d0c1d --- /dev/null +++ b/appl/reviewer/aboutdialog.ui @@ -0,0 +1,84 @@ + + + AboutDialog + + + + 0 + 0 + 423 + 289 + + + + Dialog + + + true + + + + + 20 + 20 + 381 + 221 + + + + true + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">ReFind</span> for searching files in a directory tree.</p> +<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">This is a program of the project</p> +<p align="center" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Re</span>al <span style=" font-weight:600;">Pub</span>lic <span style=" font-weight:600;">Lib</span>rary (RePubLib)</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Sources are public domain and available under</p> +<p align="center" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><a href="https://github.com/republib"><span style=" text-decoration: underline; color:#0000ff;">https://github.com/republib</span></a> </p> +<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Implemented in QT (C++) 5.x</p> +<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Icons: Mark James, <a href="http://famfamfam.com"><span style=" text-decoration: underline; color:#0000ff;">http://famfamfam.com</span></a> </p></body></html> + + + false + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse + + + + + + 310 + 250 + 93 + 27 + + + + &OK + + + + + + + pushButtonOK + clicked() + AboutDialog + close() + + + 196 + 183 + + + 199 + 108 + + + + + diff --git a/appl/reviewer/main.cpp b/appl/reviewer/main.cpp new file mode 100644 index 0000000..d6cf1aa --- /dev/null +++ b/appl/reviewer/main.cpp @@ -0,0 +1,27 @@ +/* + * main.cpp + * + * License: Public Domain + * You can use and modify this file without any restriction. + * Do what you want. + * No warranties and disclaimer of any damages. + * You also can use this license: http://www.wtfpl.net + * The latest sources: https://github.com/republib + */ + +#include +#include "base/rebase.hpp" +#include "gui/regui.hpp" +#include "mainwindow.hpp" + +int main(int argc, char *argv[]){ + QApplication app(argc, argv); + QString file = argc > 1 ? argv[1] : ""; + MainWindow w(file); + + QObject::connect(&app, SIGNAL(aboutToQuit()), &w, SLOT(closing())); + + w.show(); + + return app.exec(); +} diff --git a/appl/reviewer/mainwindow.cpp b/appl/reviewer/mainwindow.cpp new file mode 100644 index 0000000..cca307d --- /dev/null +++ b/appl/reviewer/mainwindow.cpp @@ -0,0 +1,125 @@ +/* + * mainwindow.cpp + * + * License: Public Domain + * You can use and modify this file without any restriction. + * Do what you want. + * No warranties and disclaimer of any damages. + * You also can use this license: http://www.wtfpl.net + * The latest sources: https://github.com/republib + */ + +#include "base/rebase.hpp" +#include "gui/regui.hpp" +#include "mainwindow.hpp" +#include "ui_mainwindow.h" +#include "aboutdialog.hpp" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/** + * @brief Constructor. + * + * @param parent NULL or the parent widget + */ +MainWindow::MainWindow(const QString& file, + QWidget *parent) : + QMainWindow(parent), + ui(new Ui::MainWindow), + m_statusMessage(NULL), + m_stdLabelBackgroundRole(NULL), + m_homeDir(), + m_file(file), + m_storageFile(){ + ui->setupUi(this); + initializeHome(); + m_statusMessage = new QLabel(tr("Welcome at reviewer")); + statusBar()->addWidget(m_statusMessage); +} + +/** + * @brief Destructor. + */ +MainWindow::~MainWindow(){ + delete ui; +} + +/** + * initializeHomeializes the program home directory. + */ +void MainWindow::initializeHome(){ + if (m_homeDir.isEmpty()){ + m_homeDir = QDir::home().absoluteFilePath(".review"); + } + + QDir home(m_homeDir); + if (!home.exists()){ + if (!home.mkpath(m_homeDir)){ + m_homeDir = home.tempPath() + "/.refind"; + home.mkpath(m_homeDir); + } + } + if (!m_homeDir.endsWith("/")) + m_homeDir += "/"; + m_storageFile = m_homeDir + "state.conf"; + restoreState(); +} + +/** + * Starts the about dialog. + */ +void MainWindow::about(){ + AboutDialog dialog; + dialog.exec(); +} + +void MainWindow::closing(){ + saveState(); +} + + + + +/** + * Handles the push of the button "select directory". + */ +void MainWindow::restoreState(){ + ReStateStorage storage(m_storageFile); + storage.setForm("main"); + //storage.restore(ui->comboBoxDirectory, "comboBoxDirectory", true); + storage.close(); +} + +/** + * Handles the push of the button "select directory". + */ +void MainWindow::saveState(){ + ReStateStorage storage(m_storageFile); + storage.setForm("main"); + //storage.store(ui->comboBoxDirectory, "comboBoxDirectory"); + storage.close(); +} + + +/** + * Writes a text to the status line. + * + * @param error true: the message is an error message + * @param message the text to set + */ +void MainWindow::setStatusMessage(bool error, const QString& message){ + if (m_stdLabelBackgroundRole == NULL) + m_stdLabelBackgroundRole = new QPalette::ColorRole( + m_statusMessage->backgroundRole()); + m_statusMessage->setBackgroundRole( + error ? QPalette::HighlightedText : *m_stdLabelBackgroundRole); + m_statusMessage->setText(message); +} + diff --git a/appl/reviewer/mainwindow.hpp b/appl/reviewer/mainwindow.hpp new file mode 100644 index 0000000..00c3fc8 --- /dev/null +++ b/appl/reviewer/mainwindow.hpp @@ -0,0 +1,58 @@ +/* + * mainwindow.hpp + * + * License: Public Domain + * You can use and modify this file without any restriction. + * Do what you want. + * No warranties and disclaimer of any damages. + * You also can use this license: http://www.wtfpl.net + * The latest sources: https://github.com/republib + */ + +#ifndef MAINWINDOW_HPP +#define MAINWINDOW_HPP +#ifndef REBASE_HPP +#include "base/rebase.hpp" +#endif +#include +#include +#include +#include +#include +#if ! defined GUI_REGUI_HPP_ +#include "gui/regui.hpp" +#endif +namespace Ui { +class MainWindow; +} +enum TableColumns { + TC_NODE, TC_EXT, TC_SIZE, TC_MODIFIED, TC_TYPE, TC_PATH +}; + +class MainWindow: public QMainWindow, public ReGuiValidator { + + Q_OBJECT + +public: + explicit MainWindow(const QString& file, QWidget *parent = 0); + ~MainWindow(); + +private slots: + void about(); + void closing(); + void saveState(); + +private: + void initializeHome(); + void restoreState(); + virtual void setStatusMessage(bool error, const QString& message); +private: + Ui::MainWindow *ui; + QLabel* m_statusMessage; + QPalette::ColorRole* m_stdLabelBackgroundRole; + QString m_homeDir; + QString m_file; + QString m_storageFile; +}; + +#endif // MAINWINDOW_HPP diff --git a/appl/reviewer/mainwindow.ui b/appl/reviewer/mainwindow.ui new file mode 100644 index 0000000..20bd40f --- /dev/null +++ b/appl/reviewer/mainwindow.ui @@ -0,0 +1,411 @@ + + + MainWindow + + + + 0 + 0 + 1030 + 579 + + + + RePubLib File Finder + + + + + + + + Tab 1 + + + + + + + + + 50 + 16777215 + + + + Start: + + + + + + + true + + + + + + + + 100 + 16777215 + + + + Reg.Expr. + + + + + + + + 50 + 16777215 + + + + End: + + + + + + + true + + + + + + + + 100 + 16777215 + + + + Reg.Expr + + + + + + + + 50 + 16777215 + + + + Show: + + + + + + + true + + + + + + + + 100 + 16777215 + + + + Reg.Expr. + + + + + + + + 50 + 16777215 + + + + Hide: + + + + + + + true + + + + + + + + 100 + 16777215 + + + + Reg.Expr. + + + + + + + + 50 + 16777215 + + + + Mark: + + + + + + + true + + + + + + + + 100 + 16777215 + + + + Reg.Expr. + + + + + + + &Suchen + + + + + + + + + 0 + + + + + + 100 + 16777215 + + + + + + + + + + + + + + + &Previous + + + + + + + &Next + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + First Line: + + + + + + + true + + + + + + + + + + Tab 2 + + + + + + + + + + 0 + 0 + 1030 + 23 + + + + + &File + + + + + + + + + + &Help + + + + + + &Navigate + + + + + &Edit + + + + + + + + + + + + + TopToolBarArea + + + false + + + + + + toolBar + + + TopToolBarArea + + + false + + + + + toolBar_2 + + + TopToolBarArea + + + false + + + + + + + toolBar_2 + + + TopToolBarArea + + + false + + + + + + + :/main/icons/door_in.png:/main/icons/door_in.png + + + E&xit + + + Exits the program + + + Ctrl+X + + + + + &About + + + Ctrl+Shift+A + + + + + + + + + + actionExit + triggered() + MainWindow + close() + + + -1 + -1 + + + 566 + 289 + + + + + diff --git a/appl/reviewer/reviewer.pro b/appl/reviewer/reviewer.pro new file mode 100644 index 0000000..bbe3336 --- /dev/null +++ b/appl/reviewer/reviewer.pro @@ -0,0 +1,44 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2015-04-02T23:48:19 +# +#------------------------------------------------- + +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = refind +TEMPLATE = app + +INCLUDEPATH = ../.. /usr/include/c++/4.9 + +SOURCES += main.cpp\ + mainwindow.cpp \ + ../../base/ReException.cpp \ + ../../base/ReQStringUtil.cpp \ + ../../base/ReLogger.cpp \ + aboutdialog.cpp \ + ../../gui/ReStateStorage.cpp \ + ../../gui/ReGuiValidator.cpp \ + ../../base/ReBigFile.cpp + +HEADERS += mainwindow.hpp \ + ../../base/rebase.hpp \ + ../../base/ReQStringUtil.hpp \ + ../../gui/ReStateStorage.hpp \ + aboutdialog.hpp \ + ../../gui/ReGuiValidator.hpp \ + ../../gui/regui.hpp \ + ../../base/ReBigFile.hpp + + +FORMS += mainwindow.ui \ + aboutdialog.ui + +TRANSLATIONS = reviewer_de.ts + +CODECFORSRC = UTF-8 + +RESOURCES += \ + reviewer.qrc diff --git a/appl/reviewer/reviewer.qrc b/appl/reviewer/reviewer.qrc new file mode 100644 index 0000000..5f2890a --- /dev/null +++ b/appl/reviewer/reviewer.qrc @@ -0,0 +1,24 @@ + + + icons/bullet_go.png + icons/door_in.png + icons/layout_add.png + icons/resultset_next.png + icons/sitemap_color.png + icons/arrow_turn_left.png + icons/table.png + icons/tables.png + icons/action_go.png + icons/action_paste.png + icons/folder_find.png + icons/folder_go.png + icons/folder_magnify.png + icons/folder.png + icons/wand.png + icons/cog_edit.png + icons/database_save.png + icons/disk.png + icons/wrench.png + icons/eye.png + + diff --git a/base/ReFile.cpp b/base/ReFile.cpp index ee56731..9b9551d 100644 --- a/base/ReFile.cpp +++ b/base/ReFile.cpp @@ -97,16 +97,17 @@ bool ReFile::findLine(const char* toFind, bool ignoreCase, int& lineNo, const char* ptr = start; int restLength = length - sourceLength + 1; while (restLength > 0 - && (ptr = - ignoreCase ? + && (ptr = reinterpret_cast(ignoreCase ? memchr(start, first, restLength) : - memichr(start, cc, restLength)) != NULL){ + memichr(start, first, restLength))) != NULL){ if ((ignoreCase ? memicmp(ptr, toFind, sourceLength) : memcmp(ptr, toFind, sourceLength)) == 0){ rc = true; lineNo = m_lineNo; - line = QString::fromUtf8(QByteBuffer(m_startOfLine, m_lineLength)); + QByteArray buffer(m_startOfLine, m_lineLength); + if (line == NULL) + *line = QString::fromUtf8(buffer); break; } restLength = length - (ptr - start) - sourceLength + 1; @@ -121,17 +122,19 @@ bool ReFile::findLine(const char* toFind, bool ignoreCase, int& lineNo, * @param includePattern "" or the pattern matching the result * @param includeIsRegExpr true: the pattern is a regular expression
* false: the pattern is a string without meta chars + * @param includeIgnoreCase true: includePattern is case insensitive * @param excludePattern "" or the pattern wich must not match the result * @param excludeIsRegExpr true: the exclude pattern is a regular expression
* false: the pattern is a string without meta chars - + * @param excludeIgnoreCase true: excludePattern is case insensitive * @param lineNo OUT: 0 or the line number * @param line OUT: "" or the found line * @return true: a line has been found
* false: a line has not been found */ bool ReFile::findLine(const QString& includePattern, bool includeIsRegExpr, - const QString& excludePattern, bool excludeIsRegExpr, int& lineNo, + bool includeIgnoreCase, const QString& excludePattern, + bool excludeIsRegExpr, bool includeIgnoreCase, int& lineNo, QString* line){ line = ""; lineNo = 0;