From bfebf90ecb5b3a536a20135dd1ea6ed1b159bf6b Mon Sep 17 00:00:00 2001 From: Alexander Sokolov Date: Tue, 19 Jul 2011 22:37:33 +0400 Subject: [PATCH] Razor-runner program --- CMakeLists.txt | 2 +- razorqt-runner/CMakeLists.txt | 87 +++++ razorqt-runner/commanditemmodel.cpp | 300 ++++++++++++++++ razorqt-runner/commanditemmodel.h | 116 ++++++ .../configuredialog/configuredialog.cpp | 151 ++++++++ .../configuredialog/configuredialog.h | 71 ++++ .../configuredialog/configuredialog.ui | 151 ++++++++ razorqt-runner/dialog.cpp | 338 ++++++++++++++++++ razorqt-runner/dialog.h | 76 ++++ razorqt-runner/dialog.ui | 163 +++++++++ razorqt-runner/main.cpp | 51 +++ .../themes/green/razor-runner/close-32x32.png | Bin 0 -> 791 bytes .../themes/green/razor-runner/close-48x48.png | Bin 0 -> 1255 bytes .../green/razor-runner/razor-runner.qss | 15 + .../themes/light/razor-runner/close-32x32.png | Bin 0 -> 791 bytes .../themes/light/razor-runner/close-48x48.png | Bin 0 -> 1255 bytes .../light/razor-runner/razor-runner.qss | 15 + .../translations/razor-runner_ru_RU.ts | 84 +++++ razorqt-runner/translations/translate.sh | 14 + razorqt-runner/widgets.cpp | 154 ++++++++ razorqt-runner/widgets.h | 83 +++++ 21 files changed, 1870 insertions(+), 1 deletion(-) create mode 100644 razorqt-runner/CMakeLists.txt create mode 100644 razorqt-runner/commanditemmodel.cpp create mode 100644 razorqt-runner/commanditemmodel.h create mode 100644 razorqt-runner/configuredialog/configuredialog.cpp create mode 100644 razorqt-runner/configuredialog/configuredialog.h create mode 100644 razorqt-runner/configuredialog/configuredialog.ui create mode 100644 razorqt-runner/dialog.cpp create mode 100644 razorqt-runner/dialog.h create mode 100644 razorqt-runner/dialog.ui create mode 100644 razorqt-runner/main.cpp create mode 100644 razorqt-runner/resources/themes/green/razor-runner/close-32x32.png create mode 100644 razorqt-runner/resources/themes/green/razor-runner/close-48x48.png create mode 100644 razorqt-runner/resources/themes/green/razor-runner/razor-runner.qss create mode 100644 razorqt-runner/resources/themes/light/razor-runner/close-32x32.png create mode 100644 razorqt-runner/resources/themes/light/razor-runner/close-48x48.png create mode 100644 razorqt-runner/resources/themes/light/razor-runner/razor-runner.qss create mode 100644 razorqt-runner/translations/razor-runner_ru_RU.ts create mode 100755 razorqt-runner/translations/translate.sh create mode 100644 razorqt-runner/widgets.cpp create mode 100644 razorqt-runner/widgets.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 21cd193c..0488779b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,7 +35,7 @@ add_subdirectory( razorqt-appswitcher ) add_subdirectory( razorqt-resources ) #add_subdirectory( razorqt-su ) add_subdirectory( razorqt-x11info ) - +add_subdirectory( razorqt-runner ) ########### Add uninstall target ############### diff --git a/razorqt-runner/CMakeLists.txt b/razorqt-runner/CMakeLists.txt new file mode 100644 index 00000000..433cb0d0 --- /dev/null +++ b/razorqt-runner/CMakeLists.txt @@ -0,0 +1,87 @@ +set(PROJECT razor-runner) + +set(H_FILES + dialog.h + commanditemmodel.h + widgets.h + configuredialog/configuredialog.h +) + +set(MOC_FILES + dialog.h + commanditemmodel.h + widgets.h + configuredialog/configuredialog.h +) + +set(CPP_FILES + main.cpp + dialog.cpp + commanditemmodel.cpp + widgets.cpp + configuredialog/configuredialog.cpp +) + +set(UI_FILES + dialog.ui + configuredialog/configuredialog.ui +) + +set(QRC_FILES + +) + +set(LIBRARIES + razorqt + razorqxt +) + +set(QT_USE_QTXML 1) + +set(THEMES + resources/themes +) +# Translations ********************************** +file(GLOB TS_FILES + translations/*.ts +) +#************************************************ +cmake_minimum_required( VERSION 2.6 ) + +include_directories( + . + ${CMAKE_SOURCE_DIR} + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_SOURCE_DIR}/librazorqt/ +) + + +if(NOT CMAKE_BUILD_TYPE) + set( CMAKE_BUILD_TYPE Release ) +endif (NOT CMAKE_BUILD_TYPE) + +add_definitions(-Wall) +find_package(Qt4 REQUIRED) +include(${QT_USE_FILE}) + + +set(RAZOR_SHARE_DIR ${CMAKE_INSTALL_PREFIX}/share/razor) +set(APP_SHARE_DIR ${RAZOR_SHARE_DIR}/${PROJECT}) +add_definitions(-DTRANSLATIONS_DIR=\"${APP_SHARE_DIR}\") + +#************************************************ + + +qt4_wrap_cpp(MOC_SOURCES ${MOC_FILES}) +qt4_wrap_ui(UI_HEADERS ${UI_FILES}) +qt4_add_resources(QRC_SOURCES ${QRC_FILES}) +qt4_add_translation(QM_FILES ${TS_FILES}) + +add_executable(${PROJECT} ${CPP_FILES} ${UI_FILES} ${RESOURCES} ${QRC_SOURCES} ${QM_FILES} ${MOC_SOURCES}) +add_dependencies(${PROJECT} razorqt) +target_link_libraries(${PROJECT} ${LIBRARIES} ${QT_LIBRARIES}) + +install(TARGETS ${PROJECT} RUNTIME DESTINATION bin) +install(FILES ${QM_FILES} DESTINATION ${APP_SHARE_DIR}) +install(FILES ${CONFIG_FILES} DESTINATION ${APP_SHARE_DIR}) +install(DIRECTORY ${THEMES} DESTINATION ${RAZOR_SHARE_DIR}) diff --git a/razorqt-runner/commanditemmodel.cpp b/razorqt-runner/commanditemmodel.cpp new file mode 100644 index 00000000..3adba255 --- /dev/null +++ b/razorqt-runner/commanditemmodel.cpp @@ -0,0 +1,300 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * + * Razor - a lightweight, Qt based, desktop toolset + * https://sourceforge.net/projects/razor-qt/ + * + * Copyright: 2010-2011 Razor team + * Authors: + * Alexander Sokoloff + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; only version 2 of + * the License is valid for this program. + * + * 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * END_COMMON_COPYRIGHT_HEADER */ + +#include "commanditemmodel.h" + +#include +#include +#include +#include + +#include +#include +#include +#include + + +/************************************************ + + ************************************************/ +CommandItem::CommandItem(): + QStandardItem() +{ +} + + +/************************************************ + + ************************************************/ +CommandItem::~CommandItem() +{ +} + + +/************************************************ + + ************************************************/ +void CommandItem::setText(const QString &title, const QString &comment) +{ + QString s = QString("%1
\n%2\n").arg(title, comment); + setData(s, Qt::DisplayRole); +} + + +/************************************************ + + ************************************************/ +DesktopItem::DesktopItem(const QDomElement &element): + CommandItem() +{ + setData(XdgIcon::fromTheme(element.attribute("icon")), Qt::DecorationRole); + setText(element.attribute("title"), element.attribute("genericName")); + setData(QVariant(element.attribute("comment")), Qt::ToolTipRole); + + QString command = QFileInfo(element.attribute("exec")).baseName().section(" ", 0, 0); + mSearchText = element.attribute("title") + " " + command; + mDesktopFile = element.attribute("desktopFile"); + +} + + +/************************************************ + + ************************************************/ +bool DesktopItem::run() const +{ + + XdgDesktopFile *desktop = XdgDesktopFileCache::getFile(mDesktopFile); + return desktop->startDetached(); +} + + +/************************************************ + + ************************************************/ +bool DesktopItem::compare(const QRegExp ®Exp) const +{ + QRegExp re(regExp); + + re.setCaseSensitivity(Qt::CaseInsensitive); + return mSearchText.contains(re); +} + + + +/************************************************ + + ************************************************/ +HistoryItem::HistoryItem(const QString &command): + CommandItem() +{ + setData(XdgIcon::defaultApplicationIcon(), Qt::DecorationRole); + setText(command, QObject::tr("History")); + mCommand = command; +} + + +/************************************************ + + ************************************************/ +bool HistoryItem::run() const +{ + return QProcess::startDetached(mCommand); +} + + +/************************************************ + + ************************************************/ +bool HistoryItem::compare(const QRegExp ®Exp) const +{ + QRegExp re(regExp); + + re.setCaseSensitivity(Qt::CaseSensitive); + return mCommand.contains(re); +} + + +/************************************************ + + ************************************************/ +CommandItemModel::CommandItemModel(QObject *parent) : + QSortFilterProxyModel(parent), + mSourceModel(new QStandardItemModel(this)), + mXdgMenu(new XdgMenu()) +{ + setSourceModel(mSourceModel); +// rebuild(); +} + + +/************************************************ + + ************************************************/ +CommandItemModel::~CommandItemModel() +{ +} + + +/************************************************ + + ************************************************/ +bool CommandItemModel::isOutDated() const +{ + return mXdgMenu->isOutDated(); +} + + +/************************************************ + + ************************************************/ +void CommandItemModel::rebuild() +{ + if (mXdgMenu->isOutDated()) + { + mXdgMenu->read(XdgMenu::getMenuFileName()); + + // Remove old DesktopItems. If anyone knows a better solution tell me. + for (int i = mSourceModel->rowCount()-1; i>-1; --i) + { + DesktopItem *item = dynamic_cast(mSourceModel->item(i, 0)); + if (item) + mSourceModel->removeRow(i, QModelIndex()); + } + + + rebuildMainMenu(mXdgMenu->xml().documentElement()); + } +} + + +/************************************************ + + ************************************************/ +void CommandItemModel::rebuildMainMenu(const QDomElement &xml) +{ + DomElementIterator it(xml, ""); + while(it.hasNext()) + { + QDomElement e = it.next(); + + // Build submenu ........................ + if (e.tagName() == "Menu") + rebuildMainMenu(e); + + //Build application link ................ + else if (e.tagName() == "AppLink") + { + DesktopItem *item = new DesktopItem(e); + mSourceModel->appendRow(item); + } + + } + +} + + +/************************************************ + + ************************************************/ +bool CommandItemModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const +{ + QRegExp re(filterRegExp()); + + if (re.isEmpty()) + return false; + + CommandItem *item = dynamic_cast(mSourceModel->item(sourceRow, 0)); + + if (!item) + return false; + + return item->compare(re); +} + + +/************************************************ + + ************************************************/ +const CommandItem *CommandItemModel::command(const QModelIndex &index) const +{ + if (!index.isValid()) + return 0; + + QModelIndex ind = mapToSource(index); + if (!ind.isValid()) + return 0; + + CommandItem *item = dynamic_cast(mSourceModel->item(ind.row(), 0)); + return item; +} + + +/************************************************ + + ************************************************/ +void CommandItemModel::addHistoryCommand(const QString &command) +{ + HistoryItem *item = new HistoryItem(command); + mSourceModel->appendRow(item); +} + + + +/************************************************ + + ************************************************/ +void CommandItemModel::loadHistory(const QSettings *settings) +{ + int n=0; + while (true) + { + n++; + QString command = settings->value(QString("history/command%1").arg(n)).toString(); + if (command.isEmpty()) + break; + + HistoryItem *item = new HistoryItem(command); + mSourceModel->appendRow(item); + } +} + + +/************************************************ + + ************************************************/ +void CommandItemModel::saveHistory(QSettings *settings) +{ + int n=0; + for (int i=0; irowCount(); ++i) + { + HistoryItem *item = dynamic_cast(mSourceModel->item(i, 0)); + if (item) + { + n++; + settings->setValue(QString("history/command%1").arg(n), item->command()); + } + } +} diff --git a/razorqt-runner/commanditemmodel.h b/razorqt-runner/commanditemmodel.h new file mode 100644 index 00000000..b412c7d5 --- /dev/null +++ b/razorqt-runner/commanditemmodel.h @@ -0,0 +1,116 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * + * Razor - a lightweight, Qt based, desktop toolset + * https://sourceforge.net/projects/razor-qt/ + * + * Copyright: 2010-2011 Razor team + * Authors: + * Alexander Sokoloff + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; only version 2 of + * the License is valid for this program. + * + * 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * END_COMMON_COPYRIGHT_HEADER */ + +#ifndef COMMANDITEMMODEL_H +#define COMMANDITEMMODEL_H + +#include +#include +#include +#include + +class QStandardItemModel; +class XdgMenu; +class QSettings; + +class CommandItem: public QStandardItem +{ +public: + CommandItem(); + virtual ~CommandItem(); + + virtual bool run() const = 0; + virtual bool compare(const QRegExp ®Exp) const = 0; + +protected: + void setText(const QString &title, const QString &comment); +}; + + +class DesktopItem: public CommandItem +{ +public: + DesktopItem(const QDomElement &element); + + bool run() const; + bool compare(const QRegExp ®Exp) const; + +private: + QString mSearchText; + QString mDesktopFile; +}; + + +class HistoryItem: public CommandItem +{ +public: + HistoryItem(const QString &command); + + bool run() const; + bool compare(const QRegExp ®Exp) const; + + QString command() const { return mCommand; } + +private: + QString mCommand; +}; + + +class CommandItemModel : public QSortFilterProxyModel +{ + Q_OBJECT +public: +// enum DataRoles +// { +// CaseSensitiveSearchRole = Qt::UserRole + 1, +// CaseInsensitiveSearchRole, +// FileRole +// }; + + explicit CommandItemModel(QObject *parent = 0); + virtual ~CommandItemModel(); + + bool isOutDated() const; + const CommandItem *command(const QModelIndex &index) const; + + void addHistoryCommand(const QString &command); + void loadHistory(const QSettings *settings); + void saveHistory(QSettings *settings); + +protected: + bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const; + + +public slots: + void rebuild(); + +private: + QStandardItemModel *mSourceModel; + XdgMenu *mXdgMenu; + void rebuildMainMenu(const QDomElement &xml); +}; + +#endif // COMMANDITEMMODEL_H + diff --git a/razorqt-runner/configuredialog/configuredialog.cpp b/razorqt-runner/configuredialog/configuredialog.cpp new file mode 100644 index 00000000..08a0e802 --- /dev/null +++ b/razorqt-runner/configuredialog/configuredialog.cpp @@ -0,0 +1,151 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * + * Razor - a lightweight, Qt based, desktop toolset + * https://sourceforge.net/projects/razor-qt/ + * + * Copyright: 2010-2011 Razor team + * Authors: + * Alexander Sokoloff + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; only version 2 of + * the License is valid for this program. + * + * 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * END_COMMON_COPYRIGHT_HEADER */ + + +#include "configuredialog.h" +#include "ui_configuredialog.h" + +#include + +#include +#include +#include +#include +#include +#include +#include + + + + +/************************************************ + + ************************************************/ +ConfigureDialog *ConfigureDialog::createAndShow(QSettings *settings, QWidget *parent) +{ + ConfigureDialog *dlg = new ConfigureDialog(settings, parent); + dlg->exec(); + return dlg; +} + + +/************************************************ + + ************************************************/ +ConfigureDialog::ConfigureDialog(QSettings *settings, QWidget *parent) : + QDialog(parent), + ui(new Ui::ConfigureDialog), + mSettings(settings), + mOldSettings(new RazorSettingsCache(settings)) +{ + ui->setupUi(this); + + connect(ui->buttonBox->button(QDialogButtonBox::Reset), SIGNAL(clicked()), this, SLOT(resetSettings())); + + // Position ................................. + ui->positionCbx->addItem(tr("Top edge of screen"), QVariant(ConfigureDialog::PositionTop)); + ui->positionCbx->addItem(tr("Center of screen"), QVariant(ConfigureDialog::PositionCenter)); + connect(ui->positionCbx, SIGNAL(currentIndexChanged(int)), this, SLOT(positionCbxChanged(int))); + + // Monitor .................................. + QDesktopWidget *desktop = qApp->desktop(); + + ui->monitorCbx->addItem(tr("Monitor where the mouse"), QVariant(0)); + + int monCnt = desktop->screenCount(); + for (int i=0; imonitorCbx->addItem(tr("Always on %1 monitor").arg(i+1), QVariant(i+1)); + } + ui->monitorCbx->setEnabled(monCnt > 1); + connect(ui->monitorCbx, SIGNAL(currentIndexChanged(int)), this, SLOT(monitorCbxChanged(int))); + + + // Shortcut ................................. + connect(ui->shortcutEd, SIGNAL(keySequenceChanged(QString)), this, SLOT(shortcutChanged(QString))); + settingsChanged(); +} + + +/************************************************ + + ************************************************/ +void ConfigureDialog::settingsChanged() +{ + if (mSettings->value("dialog/show_on_top", true).toBool()) + ui->positionCbx->setCurrentIndex(0); + else + ui->positionCbx->setCurrentIndex(1); + + ui->monitorCbx->setCurrentIndex(mSettings->value("dialog/monitor", 0).toInt()); + ui->shortcutEd->setKeySequence(mSettings->value("dialog/shortcut", "Alt+F2").toString()); +} + + +/************************************************ + + ************************************************/ +ConfigureDialog::~ConfigureDialog() +{ + delete ui; +} + + +/************************************************ + + ************************************************/ +void ConfigureDialog::shortcutChanged(const QString &text) +{ + mSettings->setValue("dialog/shortcut", text); +} + + +/************************************************ + + ************************************************/ +void ConfigureDialog::positionCbxChanged(int index) +{ + mSettings->setValue("dialog/show_on_top", index == 0); +} + + +/************************************************ + + ************************************************/ +void ConfigureDialog::monitorCbxChanged(int index) +{ + mSettings->setValue("dialog/monitor", index); +} + + +/************************************************ + + ************************************************/ +void ConfigureDialog::resetSettings() +{ + mOldSettings->loadToSettings(); + ui->shortcutEd->setChecked(false); + settingsChanged(); +} diff --git a/razorqt-runner/configuredialog/configuredialog.h b/razorqt-runner/configuredialog/configuredialog.h new file mode 100644 index 00000000..8ecf0617 --- /dev/null +++ b/razorqt-runner/configuredialog/configuredialog.h @@ -0,0 +1,71 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * + * Razor - a lightweight, Qt based, desktop toolset + * https://sourceforge.net/projects/razor-qt/ + * + * Copyright: 2010-2011 Razor team + * Authors: + * Alexander Sokoloff + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; only version 2 of + * the License is valid for this program. + * + * 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * END_COMMON_COPYRIGHT_HEADER */ + + +#ifndef CONFIGUREDIALOG_H +#define CONFIGUREDIALOG_H + +#include + +namespace Ui { + class ConfigureDialog; +} + +class QSettings; +class RazorSettingsCache; + +class ConfigureDialog : public QDialog +{ + Q_OBJECT + +public: + enum Position { + PositionTop, + PositionCenter + }; + + + explicit ConfigureDialog(QSettings *settings, QWidget *parent = 0); + ~ConfigureDialog(); + + static ConfigureDialog *createAndShow(QSettings *settings, QWidget *parent); + +protected: + // void closeEvent(QCloseEvent *event); + +private: + Ui::ConfigureDialog *ui; + QSettings *mSettings; + RazorSettingsCache *mOldSettings; + +private slots: + void shortcutChanged(const QString &text); + void settingsChanged(); + void positionCbxChanged(int index); + void monitorCbxChanged(int index); + void resetSettings(); +}; + +#endif // CONFIGUREDIALOG_H diff --git a/razorqt-runner/configuredialog/configuredialog.ui b/razorqt-runner/configuredialog/configuredialog.ui new file mode 100644 index 00000000..0476e2c1 --- /dev/null +++ b/razorqt-runner/configuredialog/configuredialog.ui @@ -0,0 +1,151 @@ + + + ConfigureDialog + + + + 0 + 0 + 312 + 222 + + + + Razor-runner Settings + + + + + + Appearance + + + + + + Positioning: + + + + + + + + + + Show on: + + + + + + + + + + + + + + + QFormLayout::ExpandingFieldsGrow + + + + + Shortcut: + + + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Vertical + + + + 20 + 38 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Close|QDialogButtonBox::Reset + + + + + + + + RazorShortcutButton + QToolButton +
razorqt/razorshortcutbutton.h
+
+
+ + + + buttonBox + accepted() + ConfigureDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + ConfigureDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + +
diff --git a/razorqt-runner/dialog.cpp b/razorqt-runner/dialog.cpp new file mode 100644 index 00000000..448cbf30 --- /dev/null +++ b/razorqt-runner/dialog.cpp @@ -0,0 +1,338 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * + * Razor - a lightweight, Qt based, desktop toolset + * https://sourceforge.net/projects/razor-qt/ + * + * Copyright: 2010-2011 Razor team + * Authors: + * Alexander Sokoloff + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; only version 2 of + * the License is valid for this program. + * + * 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * END_COMMON_COPYRIGHT_HEADER */ + +#include "dialog.h" +#include "ui_dialog.h" +#include "widgets.h" +#include "commanditemmodel.h" +#include "configuredialog/configuredialog.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + + +/************************************************ + + ************************************************/ +Dialog::Dialog(QWidget *parent) : + QDialog(parent, Qt::Dialog | Qt::WindowStaysOnTopHint | Qt::CustomizeWindowHint), + ui(new Ui::Dialog), + mSettings(new RazorSettings("razor-runner", this)), + mGlobalShortcut(new QxtGlobalShortcut(this)), + mCommandItemModel(new CommandItemModel(this)) +{ + ui->setupUi(this); + setStyleSheet(razorTheme->qss("razor-runner/razor-runner")); + connect(ui->closeButton, SIGNAL(clicked()), this, SLOT(hide())); + + connect(mSettings, SIGNAL(settigsChanged()), this, SLOT(applySettings())); + + mCommandItemModel->loadHistory(mSettings); + mCommandItemModel->setSortCaseSensitivity(Qt::CaseInsensitive); + + + ui->commandEd->installEventFilter(this); + ui->commandEd->setInsertPolicy(QComboBox::NoInsert); + ui->commandEd->setCompleter(0); + + connect(ui->commandEd, SIGNAL(textChanged(QString)), this, SLOT(setFilter(QString))); + connect(ui->commandEd->lineEdit(), SIGNAL(returnPressed()), this, SLOT(runCommand())); + + + ui->commandList->installEventFilter(this); + ui->commandList->setModel(mCommandItemModel); + ui->commandList->setEditTriggers(QAbstractItemView::NoEditTriggers); + connect(ui->commandList, SIGNAL(clicked(QModelIndex)), this, SLOT(runCommand())); + setFilter(""); + + ui->commandList->setItemDelegate(new HtmlDelegate(QSize(32, 32), ui->commandList)); + connect(mGlobalShortcut, SIGNAL(activated()), this, SLOT(showHide())); + + // Popup menu ............................... + QAction *a = new QAction(XdgIcon::fromTheme("configure"), tr("Configure razor-runner"), this); + connect(a, SIGNAL(triggered()), this, SLOT(showConfigDialog())); + addAction(a); + + setContextMenuPolicy(Qt::ActionsContextMenu); + // End of popup menu ........................ + + applySettings(); + resize(mSettings->value("dialog/width", 400).toInt(), size().height()); +} + + +/************************************************ + + ************************************************/ +Dialog::~Dialog() +{ + delete ui; +} + + +/************************************************ + + ************************************************/ +void Dialog::closeEvent(QCloseEvent *event) +{ + hide(); + event->ignore(); +} + + +/************************************************ + + ************************************************/ +QSize Dialog::sizeHint() const +{ + QSize size=QDialog::sizeHint(); + size.setWidth(this->size().width()); + return size; +} + + +/************************************************ + + ************************************************/ +void Dialog::resizeEvent(QResizeEvent *event) +{ + mSettings->setValue("dialog/width", size().width()); +} + + +/************************************************ + + ************************************************/ +bool Dialog::eventFilter(QObject *object, QEvent *event) +{ + if (event->type() == QEvent::KeyPress) + { + QKeyEvent *keyEvent = static_cast(event); + + if (object == ui->commandEd) + return editKeyPressEvent(keyEvent); + + if (object == ui->commandList) + return listKeyPressEvent(keyEvent); + } + + return QDialog::eventFilter(object, event); +} + + +/************************************************ + eventFilter for ui->commandEd + ************************************************/ +bool Dialog::editKeyPressEvent(QKeyEvent *event) +{ + switch (event->key()) + { + case Qt::Key_Up: + case Qt::Key_PageUp: + case Qt::Key_Down: + case Qt::Key_PageDown: + qApp->sendEvent(ui->commandList, event); + return true; + } + + return QDialog::eventFilter(ui->commandList, event); +} + + +/************************************************ + eventFilter for ui->commandList + ************************************************/ +bool Dialog::listKeyPressEvent(QKeyEvent *event) +{ + switch (event->key()) + { + case Qt::Key_Up: + case Qt::Key_PageUp: + if (ui->commandList->currentIndex().row() == 0) + { + ui->commandEd->setFocus(); + return true; + } + break; + + case Qt::Key_Left: + case Qt::Key_Right: + ui->commandEd->setFocus(); + qApp->sendEvent(ui->commandEd, event); + return true; + + default: + // Alphabetical or number key ........... + if (!event->text().isEmpty()) + { + ui->commandEd->setFocus(); + qApp->sendEvent(ui->commandEd, event); + return true; + } + } + + return QDialog::eventFilter(ui->commandEd, event); +} + + +/************************************************ + + ************************************************/ +void Dialog::showHide() +{ + if (isVisible()) + hide(); + else + { + realign(); + show(); + QApplication::setActiveWindow(this); + activateWindow(); + } +} + + +/************************************************ + + ************************************************/ +void Dialog::realign() +{ + QRect desktop; + + if (mMonitor) // Show on the specified monitor. + desktop = QApplication::desktop()->availableGeometry(mMonitor-1); + else // Follow the mouse. + desktop = QApplication::desktop()->availableGeometry(QCursor::pos()); + + + QRect rect = this->geometry(); + rect.moveCenter(desktop.center()); + if (mShowOnTop) + rect.moveTop(0); + + setGeometry(rect); +} + + +/************************************************ + + ************************************************/ +void Dialog::applySettings() +{ + // Shortcut ................................. + QKeySequence shortcut = QKeySequence::fromString(mSettings->value("dialog/shortcut", "Alt+F2").toString()); + if (shortcut.isEmpty()) + shortcut = QKeySequence::fromString("Alt+F2"); + + if (mGlobalShortcut->shortcut() != shortcut) + { + mGlobalShortcut->setShortcut(shortcut); + qDebug() << tr("Press \"%1\" to see dialog.").arg(shortcut.toString()); + } + + mShowOnTop = mSettings->value("dialog/show_on_top", true).toBool(); + + mMonitor = mSettings->value("dialog/monitor", 0).toInt(); + + realign(); + mSettings->sync(); +} + + +/************************************************ + + ************************************************/ +void Dialog::setFilter(const QString &text) +{ + if (mCommandItemModel->isOutDated()) + mCommandItemModel->rebuild(); + + mCommandItemModel->setFilterWildcard(text); + + if (mCommandItemModel->rowCount()) + { + if (!ui->commandList->currentIndex().isValid()) + ui->commandList->setCurrentIndex(mCommandItemModel->index(0, 0)); + ui->commandList->scrollTo(ui->commandList->currentIndex()); + ui->commandList->show(); + mCommandItemModel->sort(0); + } + else + { + ui->commandList->hide(); + } + + adjustSize(); +} + + +/************************************************ + + ************************************************/ +void Dialog::runCommand() +{ + bool res =false; + const CommandItem *command = mCommandItemModel->command(ui->commandList->currentIndex()); + + if (command) + { + res = command->run(); + } + else + { + QString command = ui->commandEd->currentText(); + res = QProcess::startDetached(command); + if (res) + { + mCommandItemModel->addHistoryCommand(command); + mCommandItemModel->saveHistory(mSettings); + } + } + + if (res) + { + hide(); + ui->commandEd->clearEditText(); + } + +} + + + +/************************************************ + + ************************************************/ +void Dialog::showConfigDialog() +{ + ConfigureDialog::createAndShow(mSettings, this); +} diff --git a/razorqt-runner/dialog.h b/razorqt-runner/dialog.h new file mode 100644 index 00000000..e1dfd883 --- /dev/null +++ b/razorqt-runner/dialog.h @@ -0,0 +1,76 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * + * Razor - a lightweight, Qt based, desktop toolset + * https://sourceforge.net/projects/razor-qt/ + * + * Copyright: 2010-2011 Razor team + * Authors: + * Alexander Sokoloff + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; only version 2 of + * the License is valid for this program. + * + * 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * END_COMMON_COPYRIGHT_HEADER */ + +#ifndef DIALOG_H +#define DIALOG_H + +#include + +namespace Ui { + class Dialog; +} + +class RazorSettings; +class QxtGlobalShortcut; +class CommandListView; +class CommandItemModel; + +class Dialog : public QDialog +{ + Q_OBJECT + +public: + explicit Dialog(QWidget *parent = 0); + ~Dialog(); + + QSize sizeHint() const; + +protected: + void closeEvent(QCloseEvent *event); + void resizeEvent(QResizeEvent *event); + bool eventFilter(QObject *object, QEvent *event); + bool editKeyPressEvent(QKeyEvent *event); + bool listKeyPressEvent(QKeyEvent *event); + +private: + Ui::Dialog *ui; + RazorSettings *mSettings; + QxtGlobalShortcut *mGlobalShortcut; + CommandItemModel *mCommandItemModel; + bool mShowOnTop; + int mMonitor; + + void realign(); + +private slots: + void applySettings(); + void showHide(); + void setFilter(const QString &text); + void runCommand(); + void showConfigDialog(); +}; + +#endif // DIALOG_H + diff --git a/razorqt-runner/dialog.ui b/razorqt-runner/dialog.ui new file mode 100644 index 00000000..d58938c0 --- /dev/null +++ b/razorqt-runner/dialog.ui @@ -0,0 +1,163 @@ + + + Dialog + + + + 0 + 0 + 342 + 236 + + + + + 0 + 0 + + + + + 300 + 0 + + + + Application launcher + + + false + + + + 0 + + + 0 + + + + + QFrame::NoFrame + + + QFrame::Raised + + + + -1 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + 3 + 0 + + + + + 3 + 16777215 + + + + SizeHorCursor + + + + + + + true + + + + + + + X + + + true + + + + + + + + 0 + 0 + + + + + 3 + 0 + + + + + 3 + 16777215 + + + + SizeHorCursor + + + + + + + + + + + + + + + + false + + + false + + + + + + + + + HorizSizeGrip + QWidget +
widgets.h
+ 1 +
+ + CommandComboBox + QComboBox +
widgets.h
+
+
+ + closeButton + + + +
diff --git a/razorqt-runner/main.cpp b/razorqt-runner/main.cpp new file mode 100644 index 00000000..46661283 --- /dev/null +++ b/razorqt-runner/main.cpp @@ -0,0 +1,51 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * + * Razor - a lightweight, Qt based, desktop toolset + * https://sourceforge.net/projects/razor-qt/ + * + * Copyright: 2010-2011 Razor team + * Authors: + * Alexander Sokoloff + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; only version 2 of + * the License is valid for this program. + * + * 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * END_COMMON_COPYRIGHT_HEADER */ + + +#include +#include +#include + +#include "dialog.h" + + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + a.setQuitOnLastWindowClosed(false); + + QString locale = QLocale::system().name(); + QTranslator translator; + translator.load(QString("%1/razor-runner_%3.qm").arg(TRANSLATIONS_DIR, locale)); + a.installTranslator(&translator); + + QWidget *hiddenPreviewParent = new QWidget(0, Qt::Tool); + Dialog d(hiddenPreviewParent); + //Dialog d; + //d.show(); + + return a.exec(); + +} diff --git a/razorqt-runner/resources/themes/green/razor-runner/close-32x32.png b/razorqt-runner/resources/themes/green/razor-runner/close-32x32.png new file mode 100644 index 0000000000000000000000000000000000000000..8c8a4935333a95dac55fbe81e1e8e882a1a8c9f8 GIT binary patch literal 791 zcmV+y1L*vTP)d_=Y8`K%5`11&V{bE`V3$O zFarn!u(`dNQB^hWr;{WpE=khupuUt}5K$BbN-p~qGt8aS;h8l&8@+4jjrW&n<=o@K zd?NWeIiKK;o#St7D>ol#nnwQS?|TAUTMsiBGxunQrq@>!)pSo;5TMz`k zvcA4{i{;o9!{EDzhld$Ie_sGXqW19o+@UB65JJFmEEYw+oGZvrJ&l@I3(G>fBJcu- z5CVh{jK(7e04zU$-xdG>C`z`-@@$#sIUI>Z03if+r(=C@nL7XgOG`q9=Xs700)!AS zP18OyEUjK|UfQbA00028DwonCrwP393!-D$rb`GCMB#UF!?4?iS=MWf{UE-90RRBh zyj&8~f|eFVj1U43#4Fxvwd_{QEbBErP;r2eIiS}X`)$K2o2F?K;=*J?zY zp4D=>?8_?wkX5{FpK!?^z<13_~wA`3G^@e+*~Y{^6nj{>lj9Ruc05j z_4f2yvwCEjyO!0ly{}>}c0-gTN%Zp%lmoef{CQy^b$>h_Im6-khx(^x^)j8JWQ&Pp z;z=wvC!F+qU+N#5uYAp2*9~-SY;UY6iV_c`eYCM0)HhTTUd8%%{)lD(Gl2gV;3te) VhM-N?6#@VN002ovPDHLkV1i}SWETJc literal 0 HcmV?d00001 diff --git a/razorqt-runner/resources/themes/green/razor-runner/close-48x48.png b/razorqt-runner/resources/themes/green/razor-runner/close-48x48.png new file mode 100644 index 0000000000000000000000000000000000000000..efc1ab6f925b361f9aa5d0ce05f7f46a0711582a GIT binary patch literal 1255 zcmV+CocMmXOO*#9L2NwlD|F9&++8=wY`Mky3gp-CIv( zPP@3-(u4FSMV4NduoNny#xY3+H)is-noK6o%+o_0jqbM9NpKMIg)m_zPxySEm*4Xw zh*AnSIoN4{elrwsIzs`cGZb(-Ljk8V6mU8>UVydR@c#XU&nZS>5aY*{$1A_s;XrmyqYDetXTm!pk7HuYj}d~hde}HD zsavlb$Fr-etIhvvD@hX1@$6b4=)WBfhdq=Uu$M2EkB*MhPoF&f?W!!crVwJ-@5Q+2 z=QtKvj)hydCOlK(WWw!v_xb$%{K)^oN2emGXf)#Cc@8*^hqxFEat!mW9Ts~6Kt~w{ z148KZ3_yc@= zI-c-&-RC5_@Z6dhkEO!nVc`tA+qPU*n+Byn+hMV_h>1=fl}e>A1i_UW8yjPLMS{T~ zk1}O`w#5s#eIZ zqGUT7nayM}+O-PwN{C`C83+Ve3*M5cR;xNtFayDWU_n~~s;ZJ)Za1s<0pGX4sf4Mo zPfv@ncz^-y#Ih`F9OmbCbIOZKr9uGUbUj$_d#|dh zlI`tWmStRh!vhRp1gxafX@Qvf`UfA*B*%Py7N85wFwE&FsH#dfH#f5^cFoGN+&4Tx zA4iF|hElAxG-%)kP)dPP0F2KhnynUG>a1~v3}ghXbr6k4k{-AFLZ=`==xhqr>vd8n z6tf&Nm{AzaA}0F!-C=XJVJl~ z;OO|6AfV>xsGA1>015ynF4bC<9nJXEkuuta*VZG^XmZTwW6xC{=9@p-*GI&lC1pp-(TS|Npe@nxrNU&2-yl_Uvw4DI(wG?MgsJm=;-LI~=w>m;|U zZ0MSCmuFmain5oj)oMDN2zD1Z1)tZ)Mxqn9Sr_xi+}xb4f?{tUV2pcyzdzyibf=BA zyPBp6)moM0a>@p28+S9A%#ke1nk7+I%cS?SrfGuD>to*=AOB<``u;c9Ccty92cb}K zwD%sR6zcUlQIz~Cy!A|$WsPTrxkA49qEe|6YXq!>LP3E7UAQ&@K(O1^JLhgS8V$0S zFT4S7#gh2DSj<){Rnq&+AO;{n*S7{pTU#y`ij`Kg1%_e3t5>CFzEJ#Ecq_6jYaA=g z?(gqsOQn)#!7F=vHKRkmw!>n(3Q3Z5hj+0{fN0z#^an!BCz(t}zf9Z3#YOhGRewkU zeF+HZdb{)B*~+sk{~iVy;91D2-1z^6h5}A!DByI40#0Wr;Bd_=Y8`K%5`11&V{bE`V3$O zFarn!u(`dNQB^hWr;{WpE=khupuUt}5K$BbN-p~qGt8aS;h8l&8@+4jjrW&n<=o@K zd?NWeIiKK;o#St7D>ol#nnwQS?|TAUTMsiBGxunQrq@>!)pSo;5TMz`k zvcA4{i{;o9!{EDzhld$Ie_sGXqW19o+@UB65JJFmEEYw+oGZvrJ&l@I3(G>fBJcu- z5CVh{jK(7e04zU$-xdG>C`z`-@@$#sIUI>Z03if+r(=C@nL7XgOG`q9=Xs700)!AS zP18OyEUjK|UfQbA00028DwonCrwP393!-D$rb`GCMB#UF!?4?iS=MWf{UE-90RRBh zyj&8~f|eFVj1U43#4Fxvwd_{QEbBErP;r2eIiS}X`)$K2o2F?K;=*J?zY zp4D=>?8_?wkX5{FpK!?^z<13_~wA`3G^@e+*~Y{^6nj{>lj9Ruc05j z_4f2yvwCEjyO!0ly{}>}c0-gTN%Zp%lmoef{CQy^b$>h_Im6-khx(^x^)j8JWQ&Pp z;z=wvC!F+qU+N#5uYAp2*9~-SY;UY6iV_c`eYCM0)HhTTUd8%%{)lD(Gl2gV;3te) VhM-N?6#@VN002ovPDHLkV1i}SWETJc literal 0 HcmV?d00001 diff --git a/razorqt-runner/resources/themes/light/razor-runner/close-48x48.png b/razorqt-runner/resources/themes/light/razor-runner/close-48x48.png new file mode 100644 index 0000000000000000000000000000000000000000..efc1ab6f925b361f9aa5d0ce05f7f46a0711582a GIT binary patch literal 1255 zcmV+CocMmXOO*#9L2NwlD|F9&++8=wY`Mky3gp-CIv( zPP@3-(u4FSMV4NduoNny#xY3+H)is-noK6o%+o_0jqbM9NpKMIg)m_zPxySEm*4Xw zh*AnSIoN4{elrwsIzs`cGZb(-Ljk8V6mU8>UVydR@c#XU&nZS>5aY*{$1A_s;XrmyqYDetXTm!pk7HuYj}d~hde}HD zsavlb$Fr-etIhvvD@hX1@$6b4=)WBfhdq=Uu$M2EkB*MhPoF&f?W!!crVwJ-@5Q+2 z=QtKvj)hydCOlK(WWw!v_xb$%{K)^oN2emGXf)#Cc@8*^hqxFEat!mW9Ts~6Kt~w{ z148KZ3_yc@= zI-c-&-RC5_@Z6dhkEO!nVc`tA+qPU*n+Byn+hMV_h>1=fl}e>A1i_UW8yjPLMS{T~ zk1}O`w#5s#eIZ zqGUT7nayM}+O-PwN{C`C83+Ve3*M5cR;xNtFayDWU_n~~s;ZJ)Za1s<0pGX4sf4Mo zPfv@ncz^-y#Ih`F9OmbCbIOZKr9uGUbUj$_d#|dh zlI`tWmStRh!vhRp1gxafX@Qvf`UfA*B*%Py7N85wFwE&FsH#dfH#f5^cFoGN+&4Tx zA4iF|hElAxG-%)kP)dPP0F2KhnynUG>a1~v3}ghXbr6k4k{-AFLZ=`==xhqr>vd8n z6tf&Nm{AzaA}0F!-C=XJVJl~ z;OO|6AfV>xsGA1>015ynF4bC<9nJXEkuuta*VZG^XmZTwW6xC{=9@p-*GI&lC1pp-(TS|Npe@nxrNU&2-yl_Uvw4DI(wG?MgsJm=;-LI~=w>m;|U zZ0MSCmuFmain5oj)oMDN2zD1Z1)tZ)Mxqn9Sr_xi+}xb4f?{tUV2pcyzdzyibf=BA zyPBp6)moM0a>@p28+S9A%#ke1nk7+I%cS?SrfGuD>to*=AOB<``u;c9Ccty92cb}K zwD%sR6zcUlQIz~Cy!A|$WsPTrxkA49qEe|6YXq!>LP3E7UAQ&@K(O1^JLhgS8V$0S zFT4S7#gh2DSj<){Rnq&+AO;{n*S7{pTU#y`ij`Kg1%_e3t5>CFzEJ#Ecq_6jYaA=g z?(gqsOQn)#!7F=vHKRkmw!>n(3Q3Z5hj+0{fN0z#^an!BCz(t}zf9Z3#YOhGRewkU zeF+HZdb{)B*~+sk{~iVy;91D2-1z^6h5}A!DByI40#0Wr;B + + + + ConfigureDialog + + + + Razor-runner Settings + Настройки Razor-runner + + + + + Appearance + Внешний вид + + + + + Positioning: + Позиция: + + + + + Show on: + Показывать на: + + + + + Shortcut: + Горячая клавиша: + + + + Top edge of screen + Наверху экрана + + + + Center of screen + В центре экрана + + + + Monitor where the mouse + Монитор на котором мышь + + + + Always on %1 monitor + Всегда на %1 мониторе + + + + Dialog + + + + Application launcher + Запускалка програм + + + + Configure razor-runner + Настроить razor-runner + + + + Press "%1" to see dialog. + Нажмите "%1" чтобы увидеть диалог. + + + + QObject + + + History + Из истрии + + + diff --git a/razorqt-runner/translations/translate.sh b/razorqt-runner/translations/translate.sh new file mode 100755 index 00000000..b7e3cc85 --- /dev/null +++ b/razorqt-runner/translations/translate.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +PROJECT=razor-runner +NO_OBSOLETE="-noobsolete" + +if [ "$1" = "" ]; then + TS_FILE=${PROJECT}_`echo $LANG | awk -F"." '{print($1)}'`.ts +else + TS_FILE=$1 +fi + + +lupdate $NO_OBSOLETE -recursive .. -ts $TS_FILE && linguist $TS_FILE + diff --git a/razorqt-runner/widgets.cpp b/razorqt-runner/widgets.cpp new file mode 100644 index 00000000..87c1e9a6 --- /dev/null +++ b/razorqt-runner/widgets.cpp @@ -0,0 +1,154 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * + * Razor - a lightweight, Qt based, desktop toolset + * https://sourceforge.net/projects/razor-qt/ + * + * Copyright: 2010-2011 Razor team + * Authors: + * Alexander Sokoloff + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; only version 2 of + * the License is valid for this program. + * + * 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * END_COMMON_COPYRIGHT_HEADER */ + +#include "widgets.h" + +#include +#include + + +#include +#include +#include + + + +/************************************************ + + ************************************************/ +HorizSizeGrip::HorizSizeGrip(QWidget *parent): + QWidget(parent) +{ +} + + +/************************************************ + + ************************************************/ +void HorizSizeGrip::mouseMoveEvent(QMouseEvent *event) +{ + if (!parentWidget()) + return; + + QWidget *parent = parentWidget(); + while (parent->parentWidget() && !parent->isWindow()) + { + parent = parent->parentWidget(); + } + + QRect rect = parent->geometry(); + int delta = event->globalPos().x() - rect.center().x(); + + bool isLeft = pos().x() < parent->size().width() - geometry().right(); + if (isLeft) + { + rect.setLeft(event->globalPos().x()); + rect.setRight(parent->geometry().center().x() - delta); + } + else + { + rect.setLeft(parent->geometry().center().x() - delta); + rect.setRight(event->globalPos().x()); + } + + if (rect.width() < parent->minimumWidth() || + rect.width() > parent->maximumWidth()) + return; + + parent->setGeometry(rect); +} + + +/************************************************ + + ************************************************/ +CommandComboBox::CommandComboBox(QWidget *parent) : + QComboBox(parent) +{ + +} + + + +/************************************************ + + ************************************************/ +void HtmlDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const +{ + if (!index.isValid()) + return; + + QStyleOptionViewItemV4 options = option; + initStyleOption(&options, index); + + painter->save(); + + QTextDocument doc; + doc.setHtml(options.text); + QIcon icon = options.icon; + + options.text = ""; + options.icon = QIcon(); + options.widget->style()->drawControl(QStyle::CE_ItemViewItem, &options, painter); + + // Draw icon ................................ + QSize iconSize = icon.actualSize(mIconSize); + painter->translate(options.rect.left(), options.rect.top()); + QRect iconRect = QRect(4, 4, iconSize.width(), iconSize.height()); + + icon.paint(painter, iconRect); + + doc.setTextWidth(options.rect.width() - mIconSize.width() - 10); + + // shift text right to make icon visible + painter->translate(mIconSize.width() + 8, 0); + QRect clip(0, 0, options.rect.width()-mIconSize.width() - 10, options.rect.height()); + + + painter->setClipRect(clip); + QAbstractTextDocumentLayout::PaintContext ctx; + // set text color to red for selected item + if ((option.state & QStyle::State_Selected) && (option.state & QStyle::State_Active)) + { + ctx.palette.setColor(QPalette::Text, option.palette.color(QPalette::HighlightedText)); + } + + ctx.clip = clip; + doc.documentLayout()->draw(painter, ctx); + + painter->restore(); +} + + + +/************************************************ + + ************************************************/ +CommandListView::CommandListView(QWidget *parent) : + QListView(parent) +{ + +} + diff --git a/razorqt-runner/widgets.h b/razorqt-runner/widgets.h new file mode 100644 index 00000000..c7ca43f1 --- /dev/null +++ b/razorqt-runner/widgets.h @@ -0,0 +1,83 @@ +/* BEGIN_COMMON_COPYRIGHT_HEADER + * + * Razor - a lightweight, Qt based, desktop toolset + * https://sourceforge.net/projects/razor-qt/ + * + * Copyright: 2010-2011 Razor team + * Authors: + * Alexander Sokoloff + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; only version 2 of + * the License is valid for this program. + * + * 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * END_COMMON_COPYRIGHT_HEADER */ + +#ifndef WIDGETS_H +#define WIDGETS_H + + +#include +#include +#include +#include + +class QEvent; + +class HorizSizeGrip: public QWidget +{ + Q_OBJECT +public: + HorizSizeGrip(QWidget *parent = 0); + +protected: + void mouseMoveEvent(QMouseEvent *event); + +}; + + +class CommandComboBox : public QComboBox +{ + Q_OBJECT +public: + explicit CommandComboBox(QWidget *parent = 0); +}; + + +class CommandListView : public QListView +{ + Q_OBJECT +public: + explicit CommandListView(QWidget *parent = 0); + +signals: + +public slots: + +}; + + +class HtmlDelegate : public QStyledItemDelegate +{ +public: + HtmlDelegate(const QSize iconSize, QObject* parent = 0): + QStyledItemDelegate(parent), + mIconSize(iconSize) + {} + void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const; +private: + QSize mIconSize; +}; + + +#endif // WIDGETS_H