code format
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
#include "aboutwindow.h"
|
||||
#include "ui_aboutwindow.h"
|
||||
|
||||
#include "qad_types.h"
|
||||
#include "qpiconfig.h"
|
||||
#include "ui_aboutwindow.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QFile>
|
||||
#if QT_VERSION < 0x050000
|
||||
@@ -23,44 +25,41 @@ AboutWindow::AboutWindow(QWidget * parent): QDialog(parent), ui(new Ui::AboutWin
|
||||
#ifdef ANDROID
|
||||
QDialog::setStyleSheet("font: 12pt \"DejaVu Sans\";");
|
||||
#endif
|
||||
if (!stylesheet.isEmpty())
|
||||
QDialog::setStyleSheet(stylesheet);
|
||||
if (!stylesheet.isEmpty()) QDialog::setStyleSheet(stylesheet);
|
||||
ui->setupUi(this);
|
||||
ui->labelAuthors->setOpenExternalLinks(true);
|
||||
QImage logo_im = logo;
|
||||
if (logo_im.isNull())
|
||||
logo_im.load(":/icons/splash.png");
|
||||
if (logo_im.isNull()) logo_im.load(":/icons/splash.png");
|
||||
setWindowTitle(QApplication::applicationName() + " - " + tr("About"));
|
||||
QIcon ic = QApplication::windowIcon();
|
||||
if (ic.isNull()) {
|
||||
QWidgetList tlw = QApplication::topLevelWidgets();
|
||||
foreach (QWidget * w, tlw)
|
||||
foreach(QWidget * w, tlw)
|
||||
if (!w->windowIcon().isNull()) {
|
||||
ic = w->windowIcon();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ic.isNull())
|
||||
ic = QIcon(QPixmap::fromImage(logo_im));
|
||||
if (ic.isNull()) ic = QIcon(QPixmap::fromImage(logo_im));
|
||||
setWindowIcon(ic);
|
||||
QFormLayout * lay = (QFormLayout*)(ui->groupVersions->layout());
|
||||
foreach (SSPair p, versions) {
|
||||
QFormLayout * lay = (QFormLayout *)(ui->groupVersions->layout());
|
||||
foreach(SSPair p, versions) {
|
||||
lay->addRow(p.first, new QLabel(p.second));
|
||||
}
|
||||
lay = (QFormLayout*)(ui->groupBuild->layout());
|
||||
foreach (SSPair p, builds) {
|
||||
lay = (QFormLayout *)(ui->groupBuild->layout());
|
||||
foreach(SSPair p, builds) {
|
||||
lay->addRow(p.first, new QLabel(p.second));
|
||||
}
|
||||
ui->imageView->setPixmap(QPixmap::fromImage(logo_im));
|
||||
ui->labelComment->setText(comment);
|
||||
ui->labelComment->setOpenExternalLinks(true);
|
||||
ui->labelComment->setHidden(comment.isEmpty());
|
||||
//ui->labelArch->setText(QSysInfo::currentCpuArchitecture());
|
||||
// ui->labelArch->setText(QSysInfo::currentCpuArchitecture());
|
||||
ui->labelAuthors->setText(authors());
|
||||
connect(ui->buttonQt, SIGNAL(clicked()), qApp, SLOT(aboutQt()));
|
||||
#ifdef MOBILE_VIEW
|
||||
ui->layoutMain->insertWidget(0, ui->imageView);
|
||||
//ui->verticalSpacer->changeSize(1, 1, QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||||
// ui->verticalSpacer->changeSize(1, 1, QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||||
#endif
|
||||
#ifdef MOBILE_VIEW
|
||||
ui->layoutMain->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Preferred, QSizePolicy::Expanding));
|
||||
@@ -70,18 +69,17 @@ AboutWindow::AboutWindow(QWidget * parent): QDialog(parent), ui(new Ui::AboutWin
|
||||
r = QApplication::desktop()->geometry();
|
||||
# else
|
||||
QScreen * scr =
|
||||
# if QT_VERSION >= 0x050A00
|
||||
QApplication::screenAt(QCursor::pos());
|
||||
# else
|
||||
QApplication::screens()[0];
|
||||
# endif
|
||||
# if QT_VERSION >= 0x050A00
|
||||
QApplication::screenAt(QCursor::pos());
|
||||
# else
|
||||
QApplication::screens()[0];
|
||||
# endif
|
||||
if (scr) {
|
||||
r.setSize(scr->availableSize() / 2);
|
||||
r.moveCenter(scr->availableGeometry().center());
|
||||
}
|
||||
# endif
|
||||
if (r.isValid())
|
||||
setGeometry(r);
|
||||
if (r.isValid()) setGeometry(r);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -103,7 +101,7 @@ void AboutWindow::setLogo(QString path) {
|
||||
|
||||
void AboutWindow::addVersion(QString name, QString version) {
|
||||
if (!name.endsWith(":")) name.append(":");
|
||||
foreach (const SSPair & p, versions) {
|
||||
foreach(const SSPair & p, versions) {
|
||||
if (p.first == name) return;
|
||||
}
|
||||
version.prepend("<b>");
|
||||
@@ -117,7 +115,7 @@ void AboutWindow::addVersion(QString name, QString version) {
|
||||
|
||||
void AboutWindow::addBuildInfo(QString name, QString value) {
|
||||
if (!name.endsWith(":")) name.append(":");
|
||||
foreach (const SSPair & p, builds) {
|
||||
foreach(const SSPair & p, builds) {
|
||||
if (p.first == name) return;
|
||||
}
|
||||
builds << SSPair(name, value);
|
||||
@@ -143,13 +141,13 @@ void AboutWindow::show() {
|
||||
int AboutWindow::exec() {
|
||||
#ifdef MOBILE_VIEW
|
||||
showFullScreen();
|
||||
//setWindowState(Qt::WindowFullScreen);
|
||||
// setWindowState(Qt::WindowFullScreen);
|
||||
#endif
|
||||
return QDialog::exec();
|
||||
}
|
||||
|
||||
|
||||
void AboutWindow::changeEvent(QEvent *e) {
|
||||
void AboutWindow::changeEvent(QEvent * e) {
|
||||
QDialog::changeEvent(e);
|
||||
switch (e->type()) {
|
||||
case QEvent::LanguageChange:
|
||||
@@ -202,14 +200,13 @@ QString AboutWindow::authors() {
|
||||
} else {
|
||||
QPIConfig conf(&fc);
|
||||
QPIConfig::Branch br = conf.allLeaves();
|
||||
foreach (QPIConfig::Entry * e, br) {
|
||||
foreach(QPIConfig::Entry * e, br) {
|
||||
l = e->toString().trimmed();
|
||||
if (!l.contains("<")) continue;
|
||||
QString name, mail;
|
||||
name = l.left(l.indexOf("<"));
|
||||
mail = l.mid(name.size() + 1);
|
||||
if (mail.endsWith(">"))
|
||||
mail.chop(1);
|
||||
if (mail.endsWith(">")) mail.chop(1);
|
||||
name = name.trimmed();
|
||||
mail = mail.trimmed();
|
||||
addAuthor(ret, name, mail);
|
||||
@@ -217,4 +214,3 @@ QString AboutWindow::authors() {
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,61 +1,61 @@
|
||||
/*
|
||||
QAD - Qt ADvanced
|
||||
QAD - Qt ADvanced
|
||||
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 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 Lesser General Public License for more details.
|
||||
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 Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef ABOUTWINDOW_H
|
||||
#define ABOUTWINDOW_H
|
||||
|
||||
#include <QDialog>
|
||||
#include "qad_application_export.h"
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
#define ADD_ABOUT_VERSION(lib) \
|
||||
{ \
|
||||
if (lib##_VERSION_BUILD > 0) \
|
||||
|
||||
#define ADD_ABOUT_VERSION(lib) \
|
||||
{ \
|
||||
if (lib##_VERSION_BUILD > 0) \
|
||||
AboutWindow::addVersion(#lib, lib##_VERSION_NAME " (build " + QString::number(lib##_VERSION_BUILD) + ")"); \
|
||||
else \
|
||||
AboutWindow::addVersion(#lib, lib##_VERSION_NAME); \
|
||||
else \
|
||||
AboutWindow::addVersion(#lib, lib##_VERSION_NAME); \
|
||||
}
|
||||
#define ADD_ABOUT_VERSION_NAMED(lib, label) \
|
||||
{ \
|
||||
if (lib##_VERSION_BUILD > 0) \
|
||||
#define ADD_ABOUT_VERSION_NAMED(lib, label) \
|
||||
{ \
|
||||
if (lib##_VERSION_BUILD > 0) \
|
||||
AboutWindow::addVersion(label, lib##_VERSION_NAME " (build " + QString::number(lib##_VERSION_BUILD) + ")"); \
|
||||
else \
|
||||
AboutWindow::addVersion(label, lib##_VERSION_NAME); \
|
||||
else \
|
||||
AboutWindow::addVersion(label, lib##_VERSION_NAME); \
|
||||
}
|
||||
#define ADD_ABOUT_BUILD_INFO(lib) \
|
||||
AboutWindow::addBuildInfo("Arch", lib##_ARCH); \
|
||||
#define ADD_ABOUT_BUILD_INFO(lib) \
|
||||
AboutWindow::addBuildInfo("Arch", lib##_ARCH); \
|
||||
AboutWindow::addBuildInfo("Compiler", lib##_CXX_COMPILER); \
|
||||
AboutWindow::addBuildInfo("CMake", lib##_CMAKE_VERSION); \
|
||||
AboutWindow::addBuildInfo("CMake", lib##_CMAKE_VERSION); \
|
||||
AboutWindow::addBuildInfo("Date", lib##_BUILD_DATE);
|
||||
|
||||
namespace Ui {
|
||||
class AboutWindow;
|
||||
class AboutWindow;
|
||||
}
|
||||
|
||||
class QAD_APPLICATION_EXPORT AboutWindow: public QDialog
|
||||
{
|
||||
class QAD_APPLICATION_EXPORT AboutWindow: public QDialog {
|
||||
Q_OBJECT
|
||||
typedef QPair<QString, QString> SSPair;
|
||||
explicit AboutWindow(QWidget * parent = 0);
|
||||
~AboutWindow();
|
||||
public:
|
||||
|
||||
public:
|
||||
static void setLogo(QImage im);
|
||||
static void setLogo(QString path);
|
||||
static void addVersion(QString name, QString version);
|
||||
@@ -77,7 +77,6 @@ private:
|
||||
static QImage logo;
|
||||
static QVector<SSPair> versions, builds;
|
||||
static QString stylesheet, comment;
|
||||
|
||||
};
|
||||
|
||||
#endif // ABOUTWINDOW_H
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "edockwidget.h"
|
||||
|
||||
#include "qad_types.h"
|
||||
|
||||
#include <QEvent>
|
||||
#include <QStyle>
|
||||
|
||||
@@ -18,14 +20,14 @@ void EDockWidget::setWindowTitle(const QString & title) {
|
||||
|
||||
|
||||
void EDockWidget::setWindowIcon(const QIcon & icon) {
|
||||
//#ifndef Q_OS_MACOS
|
||||
// #ifndef Q_OS_MACOS
|
||||
lbl_icon->setPixmap(icon.pixmap(QSize(256, 256)));
|
||||
QDockWidget::setWindowIcon(icon);
|
||||
if (!icon.isNull()) {
|
||||
lbl_icon->setScaledContents(true);
|
||||
lbl_icon->setFixedSize(preferredIconSize(1.5, this));
|
||||
}
|
||||
//#endif
|
||||
// #endif
|
||||
}
|
||||
|
||||
|
||||
@@ -40,32 +42,33 @@ bool EDockWidget::event(QEvent * e) {
|
||||
void EDockWidget::init() {
|
||||
header = new QFrame();
|
||||
header->setFrameShape(QFrame::StyledPanel);
|
||||
QBoxLayout * lay = new QBoxLayout(features().testFlag(QDockWidget::DockWidgetVerticalTitleBar) ? QBoxLayout::TopToBottom : QBoxLayout::LeftToRight);
|
||||
QBoxLayout * lay =
|
||||
new QBoxLayout(features().testFlag(QDockWidget::DockWidgetVerticalTitleBar) ? QBoxLayout::TopToBottom : QBoxLayout::LeftToRight);
|
||||
lay->setContentsMargins(2, 2, 2, 2);
|
||||
lay->setSpacing(2);
|
||||
lbl_icon = new QLabel();
|
||||
//#ifndef Q_OS_MACOS
|
||||
// #ifndef Q_OS_MACOS
|
||||
QIcon wi = windowIcon();
|
||||
if (!wi.isNull()) {
|
||||
lbl_icon->setPixmap(wi.pixmap(QSize(256,256)));
|
||||
/*#if QT_VERSION >= 0x500000
|
||||
if (lbl_icon->pixmap())
|
||||
const_cast<QPixmap*>(lbl_icon->pixmap())->setDevicePixelRatio(1.);
|
||||
#endif*/
|
||||
//qDebug() << windowTitle() << wi.pixmap(QSize(256,256)).size();
|
||||
lbl_icon->setPixmap(wi.pixmap(QSize(256, 256)));
|
||||
/*#if QT_VERSION >= 0x500000
|
||||
if (lbl_icon->pixmap())
|
||||
const_cast<QPixmap*>(lbl_icon->pixmap())->setDevicePixelRatio(1.);
|
||||
#endif*/
|
||||
// qDebug() << windowTitle() << wi.pixmap(QSize(256,256)).size();
|
||||
lbl_icon->setScaledContents(true);
|
||||
}
|
||||
lbl_icon->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||
//#endif
|
||||
// #endif
|
||||
lbl_title = new QLabel(windowTitle());
|
||||
lbl_title->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
||||
btn_dock = new QToolButton();
|
||||
//btn_dock->setIconSize(QSize(16, 16));
|
||||
// btn_dock->setIconSize(QSize(16, 16));
|
||||
btn_dock->setAutoRaise(true);
|
||||
btn_dock->setFocusPolicy(Qt::NoFocus);
|
||||
btn_dock->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||
btn_hide = new QToolButton();
|
||||
//btn_hide->setIconSize(QSize(16, 16));
|
||||
// btn_hide->setIconSize(QSize(16, 16));
|
||||
btn_hide->setAutoRaise(true);
|
||||
btn_hide->setFocusPolicy(Qt::NoFocus);
|
||||
btn_hide->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||
@@ -83,8 +86,8 @@ void EDockWidget::init() {
|
||||
|
||||
void EDockWidget::updateStyle() {
|
||||
QSize icon_size = preferredIconSize(0.75, this);
|
||||
int bm = 2 * style()->pixelMetric(QStyle::PM_DockWidgetTitleBarButtonMargin, 0, this);
|
||||
QSize btn_size = icon_size;
|
||||
int bm = 2 * style()->pixelMetric(QStyle::PM_DockWidgetTitleBarButtonMargin, 0, this);
|
||||
QSize btn_size = icon_size;
|
||||
btn_size += QSize(bm, bm);
|
||||
btn_dock->setIcon(style()->standardIcon(QStyle::SP_TitleBarNormalButton));
|
||||
btn_dock->setIconSize(icon_size);
|
||||
|
||||
@@ -1,59 +1,68 @@
|
||||
/*
|
||||
QAD - Qt ADvanced
|
||||
QAD - Qt ADvanced
|
||||
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 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 Lesser General Public License for more details.
|
||||
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 Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef EDOCKWIDGET_H
|
||||
#define EDOCKWIDGET_H
|
||||
|
||||
#include <QDockWidget>
|
||||
#include <QLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QIcon>
|
||||
#include <QToolButton>
|
||||
#include <QDebug>
|
||||
#include "qad_application_export.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QDockWidget>
|
||||
#include <QHBoxLayout>
|
||||
#include <QIcon>
|
||||
#include <QLabel>
|
||||
#include <QLayout>
|
||||
#include <QToolButton>
|
||||
|
||||
class QAD_APPLICATION_EXPORT EDockWidget: public QDockWidget
|
||||
{
|
||||
|
||||
class QAD_APPLICATION_EXPORT EDockWidget: public QDockWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit EDockWidget(const QString & title, QWidget * parent = 0, Qt::WindowFlags flags = Qt::WindowFlags()): QDockWidget(title, parent, flags) {init();}
|
||||
explicit EDockWidget(QWidget * parent = 0, Qt::WindowFlags flags = Qt::WindowFlags()): QDockWidget(parent, flags) {init();}
|
||||
~EDockWidget() {delete btn_hide; delete btn_dock; delete lbl_title; delete lbl_icon; delete header;}
|
||||
|
||||
explicit EDockWidget(const QString & title, QWidget * parent = 0, Qt::WindowFlags flags = Qt::WindowFlags())
|
||||
: QDockWidget(title, parent, flags) {
|
||||
init();
|
||||
}
|
||||
explicit EDockWidget(QWidget * parent = 0, Qt::WindowFlags flags = Qt::WindowFlags()): QDockWidget(parent, flags) { init(); }
|
||||
~EDockWidget() {
|
||||
delete btn_hide;
|
||||
delete btn_dock;
|
||||
delete lbl_title;
|
||||
delete lbl_icon;
|
||||
delete header;
|
||||
}
|
||||
|
||||
void setFeatures(QDockWidget::DockWidgetFeatures features);
|
||||
void setWindowTitle(const QString & title);
|
||||
void setWindowIcon(const QIcon & icon);
|
||||
|
||||
|
||||
private:
|
||||
bool event(QEvent * e);
|
||||
void init();
|
||||
void updateStyle();
|
||||
|
||||
|
||||
QFrame * header;
|
||||
QLabel * lbl_title, * lbl_icon;
|
||||
QToolButton * btn_hide, * btn_dock;
|
||||
|
||||
QLabel *lbl_title, *lbl_icon;
|
||||
QToolButton *btn_hide, *btn_dock;
|
||||
|
||||
private slots:
|
||||
void dockClicked() {setFloating(!isFloating());}
|
||||
|
||||
void dockClicked() { setFloating(!isFloating()); }
|
||||
};
|
||||
|
||||
#endif // EDOCKWIDGET_H
|
||||
|
||||
@@ -1,13 +1,19 @@
|
||||
#include "emainwindow.h"
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
#include <QMenu>
|
||||
#include <QLabel>
|
||||
#include <QMenu>
|
||||
#include <QMessageBox>
|
||||
|
||||
|
||||
EMainWindow::EMainWindow(QWidget * parent): QMainWindow(parent), action_show_all_tools(this), action_hide_all_tools(this),
|
||||
action_show_all_docks(this), action_hide_all_docks(this), first_show(true) {
|
||||
menu_recent = 0;
|
||||
EMainWindow::EMainWindow(QWidget * parent)
|
||||
: QMainWindow(parent)
|
||||
, action_show_all_tools(this)
|
||||
, action_hide_all_tools(this)
|
||||
, action_show_all_docks(this)
|
||||
, action_hide_all_docks(this)
|
||||
, first_show(true) {
|
||||
menu_recent = 0;
|
||||
action_clear_recent = new QAction(QIcon(":/icons/edit-clear.png"), tr("Clear recent list"), this);
|
||||
connect(action_clear_recent, SIGNAL(triggered()), this, SLOT(clearRecent()));
|
||||
qRegisterMetaType<Qt::DockWidgetArea>("Qt::DockWidgetArea");
|
||||
@@ -26,8 +32,7 @@ action_show_all_docks(this), action_hide_all_docks(this), first_show(true) {
|
||||
}
|
||||
|
||||
|
||||
EMainWindow::~EMainWindow() {
|
||||
}
|
||||
EMainWindow::~EMainWindow() {}
|
||||
|
||||
|
||||
void EMainWindow::setRecentFiles(const QStringList & rl) {
|
||||
@@ -39,7 +44,7 @@ void EMainWindow::setRecentFiles(const QStringList & rl) {
|
||||
|
||||
QStringList EMainWindow::recentFiles() const {
|
||||
QStringList ret;
|
||||
foreach (QAction * a, actions_recent)
|
||||
foreach(QAction * a, actions_recent)
|
||||
ret << a->data().toString();
|
||||
return ret;
|
||||
}
|
||||
@@ -56,7 +61,7 @@ void EMainWindow::showEvent(QShowEvent * e) {
|
||||
initMenus();
|
||||
if (!first_show) return;
|
||||
first_show = false;
|
||||
QList<QDockWidget * > docks(findChildren<QDockWidget * >());
|
||||
QList<QDockWidget *> docks(findChildren<QDockWidget *>());
|
||||
for (QDockWidget * d: docks) {
|
||||
connect(d, SIGNAL(dockLocationChanged(Qt::DockWidgetArea)), this, SLOT(changedDock()));
|
||||
connect(d, SIGNAL(topLevelChanged(bool)), this, SLOT(changedDock()));
|
||||
@@ -67,16 +72,18 @@ void EMainWindow::showEvent(QShowEvent * e) {
|
||||
|
||||
|
||||
void EMainWindow::closeEvent(QCloseEvent * e) {
|
||||
if (!checkSave()) e->ignore();
|
||||
else saveSession();
|
||||
if (!checkSave())
|
||||
e->ignore();
|
||||
else
|
||||
saveSession();
|
||||
}
|
||||
|
||||
|
||||
bool EMainWindow::eventFilter(QObject * o, QEvent * e) {
|
||||
if (tbars.contains((QTabBar*)o) && e->type() == QEvent::MouseButtonDblClick) {
|
||||
int tab = ((QTabBar*)o)->tabAt(((QMouseEvent * )e)->pos());
|
||||
if (tbars.contains((QTabBar *)o) && e->type() == QEvent::MouseButtonDblClick) {
|
||||
int tab = ((QTabBar *)o)->tabAt(((QMouseEvent *)e)->pos());
|
||||
if (tab >= 0) {
|
||||
QDockWidget * dock = (QDockWidget * )(((QTabBar*)o)->tabData(tab).toULongLong());
|
||||
QDockWidget * dock = (QDockWidget *)(((QTabBar *)o)->tabData(tab).toULongLong());
|
||||
if (dock) {
|
||||
dock->setFloating(true);
|
||||
return true;
|
||||
@@ -84,25 +91,25 @@ bool EMainWindow::eventFilter(QObject * o, QEvent * e) {
|
||||
}
|
||||
}
|
||||
/*if (e->type() == QEvent::Show || e->type() == QEvent::Hide) {
|
||||
if (tdocks.contains((QDockWidget*)o)) {
|
||||
changedDock();
|
||||
}
|
||||
if (tdocks.contains((QDockWidget*)o)) {
|
||||
changedDock();
|
||||
}
|
||||
}*/
|
||||
if (e->type() == QEvent::MouseButtonPress) {
|
||||
if (tbars.contains((QTabBar*)o) || tdocks.contains((QDockWidget*)o)) {
|
||||
if (tbars.contains((QTabBar *)o) || tdocks.contains((QDockWidget *)o)) {
|
||||
if (e->type() == QEvent::MouseButtonPress) {
|
||||
if (((QMouseEvent*)e)->button() == Qt::RightButton) {
|
||||
bool popup = tbars.contains((QTabBar*)o);
|
||||
if (tdocks.contains((QDockWidget*)o))
|
||||
popup = popup || ((QDockWidget*)o)->titleBarWidget()->geometry().contains(((QMouseEvent*)e)->pos());
|
||||
if (((QMouseEvent *)e)->button() == Qt::RightButton) {
|
||||
bool popup = tbars.contains((QTabBar *)o);
|
||||
if (tdocks.contains((QDockWidget *)o))
|
||||
popup = popup || ((QDockWidget *)o)->titleBarWidget()->geometry().contains(((QMouseEvent *)e)->pos());
|
||||
if (popup) {
|
||||
createPopupMenu()->popup(
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
((QMouseEvent*)e)->globalPos()
|
||||
((QMouseEvent *)e)->globalPos()
|
||||
#else
|
||||
((QMouseEvent*)e)->globalPosition().toPoint()
|
||||
((QMouseEvent *)e)->globalPosition().toPoint()
|
||||
#endif
|
||||
);
|
||||
);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -123,8 +130,7 @@ void EMainWindow::changeEvent(QEvent * e) {
|
||||
action_hide_all_docks.setText(tr("Hide all"));
|
||||
action_clear_recent->setText(tr("Clear recent list"));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,9 +143,9 @@ QMenu * EMainWindow::createPopupMenu() {
|
||||
QFont f;
|
||||
f.setBold(true);
|
||||
// Toolbars
|
||||
QList<QToolBar * > tools = findChildren<QToolBar * >();
|
||||
QList<QToolBar *> tools = findChildren<QToolBar *>();
|
||||
if (!tools.isEmpty()) {
|
||||
wa = new QWidgetAction(menuPopup);
|
||||
wa = new QWidgetAction(menuPopup);
|
||||
lbl = new QLabel();
|
||||
lbl->setFrameShape(QFrame::StyledPanel);
|
||||
lbl->setFrameShadow(QFrame::Sunken);
|
||||
@@ -162,9 +168,9 @@ QMenu * EMainWindow::createPopupMenu() {
|
||||
menuPopup->addAction(&action_hide_all_tools);
|
||||
}
|
||||
// Docks
|
||||
QList<QDockWidget * > docks = findChildren<QDockWidget * >();
|
||||
QList<QDockWidget *> docks = findChildren<QDockWidget *>();
|
||||
if (!docks.isEmpty()) {
|
||||
wa = new QWidgetAction(menuPopup);
|
||||
wa = new QWidgetAction(menuPopup);
|
||||
lbl = new QLabel();
|
||||
lbl->setFrameShape(QFrame::StyledPanel);
|
||||
lbl->setFrameShadow(QFrame::Sunken);
|
||||
@@ -193,7 +199,7 @@ QMenu * EMainWindow::createPopupMenu() {
|
||||
void EMainWindow::addToRecent(const QString & path) {
|
||||
if (path.isEmpty()) return;
|
||||
QFileInfo fi(path);
|
||||
QString fp = fi.absoluteFilePath();
|
||||
QString fp = fi.absoluteFilePath();
|
||||
bool insert = true;
|
||||
for (int i = 0; i < actions_recent.size(); ++i)
|
||||
if (actions_recent[i]->data().toString() == fp) {
|
||||
@@ -232,7 +238,7 @@ void EMainWindow::initMenus() {
|
||||
action_show_all_docks.disconnect();
|
||||
action_hide_all_docks.disconnect();
|
||||
|
||||
QList<QToolBar * > tools = findChildren<QToolBar * >();
|
||||
QList<QToolBar *> tools = findChildren<QToolBar *>();
|
||||
for (QToolBar * i: tools) {
|
||||
if (i->property("ribbon").toBool()) continue;
|
||||
i->toggleViewAction()->setIcon(i->windowIcon());
|
||||
@@ -240,7 +246,7 @@ void EMainWindow::initMenus() {
|
||||
connect(&action_hide_all_tools, SIGNAL(triggered(bool)), i, SLOT(hide()));
|
||||
}
|
||||
|
||||
QList<QDockWidget * > docks = findChildren<QDockWidget * >();
|
||||
QList<QDockWidget *> docks = findChildren<QDockWidget *>();
|
||||
for (QDockWidget * i: docks) {
|
||||
if (i->property("ribbon").toBool()) continue;
|
||||
i->toggleViewAction()->setIcon(i->windowIcon());
|
||||
@@ -248,7 +254,7 @@ void EMainWindow::initMenus() {
|
||||
connect(&action_hide_all_docks, SIGNAL(triggered(bool)), i, SLOT(hide()));
|
||||
}
|
||||
|
||||
QList<QAction * > actions = findChildren<QAction * >();
|
||||
QList<QAction *> actions = findChildren<QAction *>();
|
||||
for (QAction * i: actions)
|
||||
i->setIconVisibleInMenu(true);
|
||||
addActions(actions);
|
||||
@@ -256,8 +262,8 @@ void EMainWindow::initMenus() {
|
||||
|
||||
|
||||
void EMainWindow::initSession() {
|
||||
connect(&session, SIGNAL(loading(QPIConfig & )), this, SLOT(sessionLoading(QPIConfig & )));
|
||||
connect(&session, SIGNAL(saving(QPIConfig & )), this, SLOT(sessionSaving(QPIConfig & )));
|
||||
connect(&session, SIGNAL(loading(QPIConfig &)), this, SLOT(sessionLoading(QPIConfig &)));
|
||||
connect(&session, SIGNAL(saving(QPIConfig &)), this, SLOT(sessionSaving(QPIConfig &)));
|
||||
}
|
||||
|
||||
|
||||
@@ -279,18 +285,18 @@ bool EMainWindow::checkSave() {
|
||||
|
||||
void EMainWindow::changedDock() {
|
||||
if (isHidden()) return;
|
||||
QSet<QDockWidget * > invalid_tab_docks;
|
||||
QList<QTabBar * > tabs(findChildren<QTabBar * >());
|
||||
QList<QDockWidget * > docks = findChildren<QDockWidget * >();
|
||||
QRect geom = geometry();
|
||||
//qDebug() << "### change" << docks.size() << tabs.size();
|
||||
QSet<QDockWidget *> invalid_tab_docks;
|
||||
QList<QTabBar *> tabs(findChildren<QTabBar *>());
|
||||
QList<QDockWidget *> docks = findChildren<QDockWidget *>();
|
||||
QRect geom = geometry();
|
||||
// qDebug() << "### change" << docks.size() << tabs.size();
|
||||
for (QTabBar * t: tabs) {
|
||||
if (!t->objectName().isEmpty() || t->isHidden()) continue;
|
||||
if (!tbars.contains(t)) {
|
||||
//qDebug() << "add tab" << t;
|
||||
// qDebug() << "add tab" << t;
|
||||
tbars << t;
|
||||
connect(t, SIGNAL(tabCloseRequested(int)), this, SLOT(closeDock(int)));
|
||||
connect(t, &QObject::destroyed, this, [this,t](){tbars.removeOne(t);});
|
||||
connect(t, &QObject::destroyed, this, [this, t]() { tbars.removeOne(t); });
|
||||
t->installEventFilter(this);
|
||||
#ifndef Q_OS_MACOS
|
||||
t->setIconSize(dockTabsIconSize());
|
||||
@@ -298,12 +304,11 @@ void EMainWindow::changedDock() {
|
||||
t->setTabsClosable(true);
|
||||
}
|
||||
for (int i = 0; i < t->count(); ++i) {
|
||||
QDockWidget * dock = (QDockWidget * )t->tabData(i).toULongLong();
|
||||
//qDebug() << i << t->tabText(i) << t->isTabVisible(i) << dock;
|
||||
QDockWidget * dock = (QDockWidget *)t->tabData(i).toULongLong();
|
||||
// qDebug() << i << t->tabText(i) << t->isTabVisible(i) << dock;
|
||||
if (!dock) continue;
|
||||
if (!docks.contains(dock)) continue;
|
||||
if (!geom.intersects(t->geometry()))
|
||||
invalid_tab_docks << dock;
|
||||
if (!geom.intersects(t->geometry())) invalid_tab_docks << dock;
|
||||
#ifndef Q_OS_MACOS
|
||||
QSize is = dockTabsIconSize();
|
||||
if (t->iconSize() != is) t->setIconSize(is);
|
||||
@@ -318,24 +323,24 @@ void EMainWindow::changedDock() {
|
||||
if (!d->property("__titleWidget").isValid()) {
|
||||
d->setProperty("__titleWidget", qulonglong(ctb));
|
||||
QWidget * ntb = new QWidget();
|
||||
int m = style()->pixelMetric(QStyle::PM_DockWidgetTitleMargin);
|
||||
int m = style()->pixelMetric(QStyle::PM_DockWidgetTitleMargin);
|
||||
ntb->setLayout(new QBoxLayout(QBoxLayout::BottomToTop));
|
||||
ntb->layout()->setContentsMargins(m, m, 0, 0);
|
||||
d->setProperty("__titleEmptyWidget", qulonglong(ntb));
|
||||
}
|
||||
if (!tdocks.contains(d)) {
|
||||
//qDebug() << "add dock" << d;
|
||||
// qDebug() << "add dock" << d;
|
||||
tdocks << d;
|
||||
connect(d, &QObject::destroyed, this, [this,d](){tdocks.removeOne(d);});
|
||||
connect(d, &QObject::destroyed, this, [this, d]() { tdocks.removeOne(d); });
|
||||
d->installEventFilter(this);
|
||||
}
|
||||
//qDebug() << d->windowTitle() << tabifiedDockWidgets(d);
|
||||
// qDebug() << d->windowTitle() << tabifiedDockWidgets(d);
|
||||
if (tabifiedDockWidgets(d).isEmpty() || invalid_tab_docks.contains(d)) {
|
||||
if (d->titleBarWidget() != (QWidget * )(d->property("__titleWidget").toULongLong()))
|
||||
d->setTitleBarWidget((QWidget * )(d->property("__titleWidget").toULongLong()));
|
||||
if (d->titleBarWidget() != (QWidget *)(d->property("__titleWidget").toULongLong()))
|
||||
d->setTitleBarWidget((QWidget *)(d->property("__titleWidget").toULongLong()));
|
||||
} else {
|
||||
if (d->titleBarWidget() != (QWidget * )(d->property("__titleEmptyWidget").toULongLong())) {
|
||||
d->setTitleBarWidget((QWidget * )(d->property("__titleEmptyWidget").toULongLong()));
|
||||
if (d->titleBarWidget() != (QWidget *)(d->property("__titleEmptyWidget").toULongLong())) {
|
||||
d->setTitleBarWidget((QWidget *)(d->property("__titleEmptyWidget").toULongLong()));
|
||||
d->layout()->setContentsMargins(0, 20, 0, 0);
|
||||
}
|
||||
}
|
||||
@@ -344,20 +349,19 @@ void EMainWindow::changedDock() {
|
||||
|
||||
|
||||
void EMainWindow::closeDock(int index) {
|
||||
QDockWidget * dock = (QDockWidget * )((QTabBar*)sender())->tabData(index).toULongLong();
|
||||
QDockWidget * dock = (QDockWidget *)((QTabBar *)sender())->tabData(index).toULongLong();
|
||||
if (dock == 0) return;
|
||||
dock->close();
|
||||
}
|
||||
|
||||
|
||||
void EMainWindow::recentTriggered() {
|
||||
QAction * a = qobject_cast<QAction * >(sender());
|
||||
QAction * a = qobject_cast<QAction *>(sender());
|
||||
if (!a) return;
|
||||
QString path = a->data().toString();
|
||||
if (path.isEmpty()) return;
|
||||
if (!checkSave()) return;
|
||||
if (load(path))
|
||||
addToRecent(path);
|
||||
if (load(path)) addToRecent(path);
|
||||
}
|
||||
|
||||
|
||||
@@ -379,31 +383,32 @@ void EMainWindow::openFile() {
|
||||
if (!checkSave()) return;
|
||||
QString ret = QFileDialog::getOpenFileName(this, tr("Select file to open"), file_name, loadFilter());
|
||||
if (ret.isEmpty()) return;
|
||||
if (load(ret))
|
||||
addToRecent(ret);
|
||||
if (load(ret)) addToRecent(ret);
|
||||
}
|
||||
|
||||
|
||||
void EMainWindow::openFiles() {
|
||||
if (!checkSave()) return;
|
||||
QStringList ret = QFileDialog::getOpenFileNames(this, tr("Select files to open"), file_name, loadFilter());
|
||||
foreach (QString s, ret) {
|
||||
if (load(s))
|
||||
addToRecent(s);
|
||||
foreach(QString s, ret) {
|
||||
if (load(s)) addToRecent(s);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool EMainWindow::saveFile(bool ask) {
|
||||
if (ask) {
|
||||
int ret = QMessageBox::question(this, windowTitle(), tr("Save changes%1?").arg(!file_name.isEmpty() ? (tr(" in") + " \"" + file_name + "\"") : ""), QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Save);
|
||||
int ret = QMessageBox::question(this,
|
||||
windowTitle(),
|
||||
tr("Save changes%1?").arg(!file_name.isEmpty() ? (tr(" in") + " \"" + file_name + "\"") : ""),
|
||||
QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel,
|
||||
QMessageBox::Save);
|
||||
if (ret == QMessageBox::Cancel) return false;
|
||||
if (ret == QMessageBox::Save) return saveFile();
|
||||
return true;
|
||||
}
|
||||
if (file_name.isEmpty()) return saveAsFile();
|
||||
if (save(file_name))
|
||||
addToRecent(file_name);
|
||||
if (save(file_name)) addToRecent(file_name);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -411,8 +416,7 @@ bool EMainWindow::saveFile(bool ask) {
|
||||
bool EMainWindow::saveAsFile() {
|
||||
QString ret = QFileDialog::getSaveFileName(this, tr("Select file to save"), file_name, saveFilter());
|
||||
if (ret.isEmpty()) return false;
|
||||
if (save(ret))
|
||||
addToRecent(ret);
|
||||
if (save(ret)) addToRecent(ret);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,43 +1,45 @@
|
||||
/*
|
||||
QAD - Qt ADvanced
|
||||
QAD - Qt ADvanced
|
||||
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 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 Lesser General Public License for more details.
|
||||
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 Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef EMAINWINDOW_H
|
||||
#define EMAINWINDOW_H
|
||||
|
||||
#include "qad_application_export.h"
|
||||
#include "ribbon.h"
|
||||
#include "session_manager.h"
|
||||
|
||||
#include <QClipboard>
|
||||
#include <QColorDialog>
|
||||
#include <QInputDialog>
|
||||
#include <QRadioButton>
|
||||
#include <QSplitter>
|
||||
#include <QThread>
|
||||
#include <QTime>
|
||||
#include <QTranslator>
|
||||
#include <QUrl>
|
||||
#include <QInputDialog>
|
||||
#include <QClipboard>
|
||||
#include <QRadioButton>
|
||||
#include <QThread>
|
||||
#include <QColorDialog>
|
||||
#include <QTime>
|
||||
#include <QSplitter>
|
||||
#include "session_manager.h"
|
||||
#include "ribbon.h"
|
||||
#include "qad_application_export.h"
|
||||
|
||||
|
||||
class QAD_APPLICATION_EXPORT UAction: public QAction {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
UAction(int ind,const QString & text, QObject * parent): QAction(text, parent) {
|
||||
UAction(int ind, const QString & text, QObject * parent): QAction(text, parent) {
|
||||
index = ind;
|
||||
connect(this, SIGNAL(triggered()), this, SLOT(triggered()));
|
||||
connect(this, SIGNAL(toggled(bool)), this, SLOT(toggled(bool)));
|
||||
@@ -50,16 +52,17 @@ public:
|
||||
connect(this, SIGNAL(hovered()), this, SLOT(hovered()));
|
||||
}
|
||||
public slots:
|
||||
void show() {setVisible(true);}
|
||||
void hide() {setVisible(false);}
|
||||
void setCheckedTrue() {setChecked(true);}
|
||||
void setCheckedFalse() {setChecked(false);}
|
||||
void show() { setVisible(true); }
|
||||
void hide() { setVisible(false); }
|
||||
void setCheckedTrue() { setChecked(true); }
|
||||
void setCheckedFalse() { setChecked(false); }
|
||||
|
||||
private:
|
||||
int index;
|
||||
private slots:
|
||||
void triggered() {emit itriggered(this, index);}
|
||||
void toggled(bool t) {emit itoggled(t, this, index);}
|
||||
void hovered() {emit ihovered(this);}
|
||||
void triggered() { emit itriggered(this, index); }
|
||||
void toggled(bool t) { emit itoggled(t, this, index); }
|
||||
void hovered() { emit ihovered(this); }
|
||||
signals:
|
||||
void itriggered(QAction *, int);
|
||||
void itoggled(bool, QAction *, int);
|
||||
@@ -67,55 +70,63 @@ signals:
|
||||
};
|
||||
|
||||
|
||||
class QAD_APPLICATION_EXPORT EMainWindow: public QMainWindow
|
||||
{
|
||||
class QAD_APPLICATION_EXPORT EMainWindow: public QMainWindow {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(int maxRecentItems READ maxRecentItems WRITE setMaxRecentItems)
|
||||
|
||||
public:
|
||||
EMainWindow(QWidget * parent = 0);
|
||||
~EMainWindow();
|
||||
|
||||
virtual void reset(bool full = false) {}
|
||||
virtual bool load(const QString & path) {return true;}
|
||||
virtual bool save(const QString & path) {return true;}
|
||||
virtual bool load(const QString & path) { return true; }
|
||||
virtual bool save(const QString & path) { return true; }
|
||||
|
||||
void addSeparator() {}
|
||||
void setRecentFiles(const QStringList & rl);
|
||||
QStringList recentFiles() const;
|
||||
void setRecentMenu(QMenu * m);
|
||||
|
||||
int maxRecentItems() const {return max_recent;}
|
||||
int maxRecentItems() const { return max_recent; }
|
||||
|
||||
protected:
|
||||
// Qt`s overloaded
|
||||
void showEvent(QShowEvent * );
|
||||
void closeEvent(QCloseEvent * );
|
||||
void showEvent(QShowEvent *);
|
||||
void closeEvent(QCloseEvent *);
|
||||
bool eventFilter(QObject * o, QEvent * e);
|
||||
void changeEvent(QEvent * e);
|
||||
QMenu * createPopupMenu();
|
||||
void addToRecent(const QString & path);
|
||||
void prepareRecent();
|
||||
|
||||
void init(const QString & config) {session.setFile(config); initMenus(); initSession(); loadSession();} // unusable
|
||||
void init(const QString & config) {
|
||||
session.setFile(config);
|
||||
initMenus();
|
||||
initSession();
|
||||
loadSession();
|
||||
} // unusable
|
||||
void saveSession();
|
||||
void loadSession();
|
||||
virtual void savingSession(QPIConfig & conf) {}
|
||||
virtual void loadingSession(QPIConfig & conf) {}
|
||||
virtual QSize dockTabsIconSize() const {return iconSize();}
|
||||
virtual QString loadFilter() {return "All files(*)";}
|
||||
virtual QString saveFilter() {return "All files(*)";}
|
||||
virtual QSize dockTabsIconSize() const { return iconSize(); }
|
||||
virtual QString loadFilter() { return "All files(*)"; }
|
||||
virtual QString saveFilter() { return "All files(*)"; }
|
||||
|
||||
bool checkSave();
|
||||
void setChanged(bool yes = true) {isChanged = yes; setWindowModified(yes);}
|
||||
void setChanged(bool yes = true) {
|
||||
isChanged = yes;
|
||||
setWindowModified(yes);
|
||||
}
|
||||
|
||||
void initMenus();
|
||||
void initSession();
|
||||
|
||||
QAction action_show_all_tools, action_hide_all_tools, action_show_all_docks, action_hide_all_docks;
|
||||
QString file_name;
|
||||
QList<QTabBar * > tbars;
|
||||
QList<QDockWidget * > tdocks;
|
||||
QList<QAction * > actions_recent;
|
||||
QList<QTabBar *> tbars;
|
||||
QList<QDockWidget *> tdocks;
|
||||
QList<QAction *> actions_recent;
|
||||
QAction * action_clear_recent;
|
||||
QMenu * menu_recent;
|
||||
SessionManager session;
|
||||
@@ -124,24 +135,23 @@ protected:
|
||||
|
||||
private slots:
|
||||
void changedDock();
|
||||
void sessionLoading(QPIConfig & conf) {loadingSession(conf);}
|
||||
void sessionSaving(QPIConfig & conf) {savingSession(conf);}
|
||||
void sessionLoading(QPIConfig & conf) { loadingSession(conf); }
|
||||
void sessionSaving(QPIConfig & conf) { savingSession(conf); }
|
||||
void closeDock(int index);
|
||||
void recentTriggered();
|
||||
|
||||
public slots:
|
||||
void setMaxRecentItems(int mr);
|
||||
void changed() {setChanged(true);}
|
||||
void changed() { setChanged(true); }
|
||||
void newFile();
|
||||
void openFile();
|
||||
void openFiles();
|
||||
bool saveFile(bool ask);
|
||||
bool saveFile() {return saveFile(false);}
|
||||
bool saveFile() { return saveFile(false); }
|
||||
bool saveAsFile();
|
||||
void clearRecent();
|
||||
|
||||
signals:
|
||||
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "etabwidget.h"
|
||||
|
||||
|
||||
ETabWidget::ETabWidget(QWidget* parent): QTabWidget(parent) {
|
||||
ETabWidget::ETabWidget(QWidget * parent): QTabWidget(parent) {
|
||||
tabBar()->setMouseTracking(true);
|
||||
tabBar()->installEventFilter(this);
|
||||
}
|
||||
@@ -9,26 +9,27 @@ ETabWidget::ETabWidget(QWidget* parent): QTabWidget(parent) {
|
||||
|
||||
void ETabWidget::retranslate() {
|
||||
for (int i = 0; i < buttons.size(); ++i)
|
||||
buttons[i].toolTip = QApplication::translate("MainWindow", buttons[i].srcToolTip.toUtf8(), 0/*, QCoreApplication::UnicodeUTF8*/);
|
||||
QList<QToolButton * > bl = findChildren<QToolButton * >();
|
||||
foreach (QToolButton * i, bl)
|
||||
i->setToolTip(QApplication::translate("MainWindow", i->property("sourceToolTip").toString().toUtf8(), 0/*, QCoreApplication::UnicodeUTF8*/));
|
||||
buttons[i].toolTip = QApplication::translate("MainWindow", buttons[i].srcToolTip.toUtf8(), 0 /*, QCoreApplication::UnicodeUTF8*/);
|
||||
QList<QToolButton *> bl = findChildren<QToolButton *>();
|
||||
foreach(QToolButton * i, bl)
|
||||
i->setToolTip(
|
||||
QApplication::translate("MainWindow", i->property("sourceToolTip").toString().toUtf8(), 0 /*, QCoreApplication::UnicodeUTF8*/));
|
||||
}
|
||||
|
||||
|
||||
int ETabWidget::addTab(QWidget * page, const QIcon & icon, const QString & label) {
|
||||
int ret = QTabWidget::addTab(page, icon, label);
|
||||
int ret = QTabWidget::addTab(page, icon, label);
|
||||
QWidget * w = new QWidget();
|
||||
w->setLayout(new QBoxLayout(QBoxLayout::RightToLeft));
|
||||
w->layout()->setContentsMargins(0, 0, 0, 0);
|
||||
w->layout()->setSpacing(2);
|
||||
QToolButton * b;
|
||||
foreach (const TabButton & i, buttons) {
|
||||
foreach(const TabButton & i, buttons) {
|
||||
b = new QToolButton();
|
||||
b->setToolTip(i.toolTip);
|
||||
b->setIconSize(QSize(16, 16));
|
||||
b->setIcon(i.icon);
|
||||
//b->setFlat(true);
|
||||
// b->setFlat(true);
|
||||
b->setProperty("sourceToolTip", i.toolTip);
|
||||
b->setProperty("buttonRole", i.role);
|
||||
connect(b, SIGNAL(clicked(bool)), this, SLOT(buttonClicked()));
|
||||
@@ -41,14 +42,12 @@ int ETabWidget::addTab(QWidget * page, const QIcon & icon, const QString & label
|
||||
|
||||
|
||||
void ETabWidget::setButtonVisible(int role, bool yes) {
|
||||
QList<QToolButton * > bl = findChildren<QToolButton * >();
|
||||
foreach (QToolButton * i, bl)
|
||||
if (i->property("buttonRole").toInt() == role)
|
||||
i->setVisible(yes);
|
||||
QList<QToolButton *> bl = findChildren<QToolButton *>();
|
||||
foreach(QToolButton * i, bl)
|
||||
if (i->property("buttonRole").toInt() == role) i->setVisible(yes);
|
||||
QWidget * w;
|
||||
for (int i = 0; i < buttons.size(); ++i) {
|
||||
if (buttons[i].role == role)
|
||||
buttons[i].visible = yes;
|
||||
if (buttons[i].role == role) buttons[i].visible = yes;
|
||||
w = tabBar()->tabButton(i, QTabBar::RightSide);
|
||||
if (w != 0) w->adjustSize();
|
||||
}
|
||||
@@ -57,19 +56,19 @@ void ETabWidget::setButtonVisible(int role, bool yes) {
|
||||
|
||||
/*
|
||||
void ETabWidget::removeTab(int index) {
|
||||
tbs.removeAll(qobject_cast<QToolButton * >(tabBar()->tabButton(index, QTabBar::RightSide)->layout()->itemAt(1)->widget()));
|
||||
tbs.removeAll(qobject_cast<QToolButton * >(tabBar()->tabButton(index, QTabBar::RightSide)->layout()->itemAt(0)->widget()));
|
||||
QTabWidget::removeTab(index);
|
||||
tbs.removeAll(qobject_cast<QToolButton * >(tabBar()->tabButton(index, QTabBar::RightSide)->layout()->itemAt(1)->widget()));
|
||||
tbs.removeAll(qobject_cast<QToolButton * >(tabBar()->tabButton(index, QTabBar::RightSide)->layout()->itemAt(0)->widget()));
|
||||
QTabWidget::removeTab(index);
|
||||
}
|
||||
*/
|
||||
|
||||
bool ETabWidget::eventFilter(QObject * o, QEvent * e) {
|
||||
static int prev = -1;
|
||||
if (e->type() == QEvent::MouseMove) {
|
||||
QTabBar * t = qobject_cast<QTabBar * >(o);
|
||||
QTabBar * t = qobject_cast<QTabBar *>(o);
|
||||
if (t == 0) return QTabWidget::eventFilter(o, e);
|
||||
for (int i = 0; i < count(); ++i)
|
||||
if (t->tabRect(i).contains(((QMouseEvent * )e)->pos())) {
|
||||
if (t->tabRect(i).contains(((QMouseEvent *)e)->pos())) {
|
||||
if (i != prev) {
|
||||
prev = i;
|
||||
emit tabHovered(i);
|
||||
@@ -94,17 +93,14 @@ bool ETabWidget::eventFilter(QObject * o, QEvent * e) {
|
||||
void ETabWidget::changeEvent(QEvent * e) {
|
||||
QTabWidget::changeEvent(e);
|
||||
switch (e->type()) {
|
||||
case QEvent::LanguageChange:
|
||||
retranslate();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case QEvent::LanguageChange: retranslate(); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ETabWidget::buttonClicked() {
|
||||
QToolButton * s = qobject_cast<QToolButton * >(sender());
|
||||
QToolButton * s = qobject_cast<QToolButton *>(sender());
|
||||
if (s == 0) return;
|
||||
QWidget * pw = s->parentWidget();
|
||||
if (pw == 0) return;
|
||||
|
||||
@@ -1,75 +1,81 @@
|
||||
/*
|
||||
QAD - Qt ADvanced
|
||||
QAD - Qt ADvanced
|
||||
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 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 Lesser General Public License for more details.
|
||||
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 Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef ETABWIDGET_H
|
||||
#define ETABWIDGET_H
|
||||
|
||||
#include <QTabWidget>
|
||||
#include <QDebug>
|
||||
#include <QTabBar>
|
||||
#include <QMouseEvent>
|
||||
#include <QEvent>
|
||||
#include <QToolButton>
|
||||
#include <QPushButton>
|
||||
#include <QLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QApplication>
|
||||
#include "qad_application_export.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDebug>
|
||||
#include <QEvent>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLayout>
|
||||
#include <QMouseEvent>
|
||||
#include <QPushButton>
|
||||
#include <QTabBar>
|
||||
#include <QTabWidget>
|
||||
#include <QToolButton>
|
||||
|
||||
class QAD_APPLICATION_EXPORT ETabWidget: public QTabWidget
|
||||
{
|
||||
|
||||
class QAD_APPLICATION_EXPORT ETabWidget: public QTabWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ETabWidget(QWidget * parent = 0);
|
||||
|
||||
|
||||
void retranslate();
|
||||
void addTabButton(int role, const QIcon & icon, const QString & toolTip = QString()) {buttons << TabButton(role, icon, toolTip);}
|
||||
void addTabButton(int role, const QIcon & icon, const QString & toolTip = QString()) { buttons << TabButton(role, icon, toolTip); }
|
||||
int addTab(QWidget * page, const QIcon & icon, const QString & label);
|
||||
int addTab(QWidget * page, const QString & label) {return addTab(page, QIcon(), label);}
|
||||
int addTab(QWidget * page, const QString & label) { return addTab(page, QIcon(), label); }
|
||||
void setButtonVisible(int role, bool yes);
|
||||
|
||||
|
||||
private:
|
||||
bool eventFilter(QObject * o, QEvent * e);
|
||||
void tabInserted(int) {emit countChanged();}
|
||||
void tabRemoved(int) {emit countChanged();}
|
||||
void tabInserted(int) { emit countChanged(); }
|
||||
void tabRemoved(int) { emit countChanged(); }
|
||||
void changeEvent(QEvent * e);
|
||||
|
||||
|
||||
struct QAD_APPLICATION_EXPORT TabButton {
|
||||
TabButton(int r, const QIcon & i, const QString & t) {role = r; icon = i; visible = true; srcToolTip = t; toolTip = QApplication::translate("MainWindow", t.toUtf8(), 0/*, QCoreApplication::UnicodeUTF8*/);}
|
||||
TabButton(int r, const QIcon & i, const QString & t) {
|
||||
role = r;
|
||||
icon = i;
|
||||
visible = true;
|
||||
srcToolTip = t;
|
||||
toolTip = QApplication::translate("MainWindow", t.toUtf8(), 0 /*, QCoreApplication::UnicodeUTF8*/);
|
||||
}
|
||||
int role;
|
||||
bool visible;
|
||||
QIcon icon;
|
||||
QString srcToolTip;
|
||||
QString toolTip;
|
||||
};
|
||||
|
||||
|
||||
QList<TabButton> buttons;
|
||||
|
||||
|
||||
private slots:
|
||||
void buttonClicked();
|
||||
|
||||
|
||||
signals:
|
||||
void countChanged();
|
||||
void tabHovered(int tab);
|
||||
void tabButtonClicked(int tab, int role);
|
||||
|
||||
};
|
||||
|
||||
#endif // ETABWIDGET_H
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
#include "historyview.h"
|
||||
#include <QScrollBar>
|
||||
|
||||
#include <QEvent>
|
||||
#include <QScrollBar>
|
||||
|
||||
|
||||
HistoryView::HistoryView(QWidget* parent): QListWidget(parent) {
|
||||
HistoryView::HistoryView(QWidget * parent): QListWidget(parent) {
|
||||
setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
|
||||
setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
|
||||
setSelectionMode(QAbstractItemView::MultiSelection);
|
||||
setEditTriggers(NoEditTriggers);
|
||||
active_ = true;
|
||||
active_ = true;
|
||||
duplicates_ = false;
|
||||
index = 0;
|
||||
index = 0;
|
||||
setLimit(32);
|
||||
setHistoryColor(palette().color(QPalette::Highlight));
|
||||
connect(this, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(itemClicked(QListWidgetItem*)));
|
||||
connect(this, SIGNAL(itemClicked(QListWidgetItem *)), this, SLOT(itemClicked(QListWidgetItem *)));
|
||||
connect(this, SIGNAL(itemSelectionChanged()), this, SLOT(itemSelectionChanged()));
|
||||
registerAction(-1, tr("History cleared"), QImage(":/icons/clear-history.png"));
|
||||
}
|
||||
|
||||
|
||||
HistoryView::~HistoryView() {
|
||||
}
|
||||
HistoryView::~HistoryView() {}
|
||||
|
||||
|
||||
QByteArray HistoryView::current() const {
|
||||
@@ -37,8 +37,7 @@ void HistoryView::addEntry(int action, int count_, const QString & suffix) {
|
||||
QByteArray ba;
|
||||
emit commandRequest(ba);
|
||||
if (!duplicates_)
|
||||
if (current() == ba)
|
||||
return;
|
||||
if (current() == ba) return;
|
||||
int cnt = count();
|
||||
for (int i = index; i < cnt; ++i)
|
||||
if (i >= 0) delete takeItem(index);
|
||||
@@ -94,11 +93,8 @@ void HistoryView::checkLimit() {
|
||||
void HistoryView::changeEvent(QEvent * e) {
|
||||
QListWidget::changeEvent(e);
|
||||
switch (e->type()) {
|
||||
case QEvent::LanguageChange:
|
||||
actions_[-1].text = tr("History cleared");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case QEvent::LanguageChange: actions_[-1].text = tr("History cleared"); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,7 +103,7 @@ void HistoryView::itemClicked(QListWidgetItem * item) {
|
||||
if (!active_) return;
|
||||
if (index == row(item) + 1) return;
|
||||
index = row(item) + 1;
|
||||
//qDebug() << actions[index - 1].command;
|
||||
// qDebug() << actions[index - 1].command;
|
||||
emit commandExecute(history_[index - 1].command);
|
||||
emit changed();
|
||||
itemSelectionChanged();
|
||||
@@ -117,7 +113,7 @@ void HistoryView::itemClicked(QListWidgetItem * item) {
|
||||
void HistoryView::itemSelectionChanged() {
|
||||
if (!active_) return;
|
||||
if (index < 1) index = 1;
|
||||
//qDebug() << "changed" << count();
|
||||
// qDebug() << "changed" << count();
|
||||
int vpos = verticalScrollBar()->value();
|
||||
blockSignals(true);
|
||||
setCurrentItem(item(index - 1));
|
||||
|
||||
@@ -1,50 +1,51 @@
|
||||
/*
|
||||
QAD - Qt ADvanced
|
||||
QAD - Qt ADvanced
|
||||
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 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 Lesser General Public License for more details.
|
||||
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 Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef HISTORYVIEW_H
|
||||
#define HISTORYVIEW_H
|
||||
|
||||
#include <QListWidget>
|
||||
#include <QDebug>
|
||||
#include "qad_application_export.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QListWidget>
|
||||
|
||||
class QAD_APPLICATION_EXPORT HistoryView: public QListWidget
|
||||
{
|
||||
|
||||
class QAD_APPLICATION_EXPORT HistoryView: public QListWidget {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool active READ isActive WRITE setActive)
|
||||
Q_PROPERTY(bool duplicatesEnabled READ isDuplicatesEnabled WRITE setDuplicatesEnabled)
|
||||
Q_PROPERTY(int limit READ limit WRITE setLimit)
|
||||
Q_PROPERTY(QColor historyColor READ historyColor WRITE setHistoryColor)
|
||||
|
||||
public:
|
||||
explicit HistoryView(QWidget * parent = 0);
|
||||
~HistoryView();
|
||||
|
||||
bool isActive() const {return active_;}
|
||||
bool isDuplicatesEnabled() const {return duplicates_;}
|
||||
int limit() const {return limit_;}
|
||||
QColor historyColor() const {return color_;}
|
||||
|
||||
bool isActive() const { return active_; }
|
||||
bool isDuplicatesEnabled() const { return duplicates_; }
|
||||
int limit() const { return limit_; }
|
||||
QColor historyColor() const { return color_; }
|
||||
QByteArray current() const;
|
||||
|
||||
|
||||
void addEntry(int action, int count = 0, const QString & suffix = QString());
|
||||
void registerAction(int action, const QString & text, const QImage & icon = QImage());
|
||||
|
||||
|
||||
private:
|
||||
struct QAD_APPLICATION_EXPORT Action {
|
||||
Action(int i = -1, const QString & t = QString(), const QImage & c = QImage()): id(i), text(t) {
|
||||
@@ -63,31 +64,31 @@ private:
|
||||
int action;
|
||||
QByteArray command;
|
||||
};
|
||||
|
||||
|
||||
void checkLimit();
|
||||
void changeEvent(QEvent * e);
|
||||
QString actionText(int action, int count_);
|
||||
|
||||
|
||||
QMap<int, Action> actions_;
|
||||
QVector<Entry> history_;
|
||||
QColor color_;
|
||||
bool active_, duplicates_;
|
||||
int index, limit_;
|
||||
|
||||
|
||||
public slots:
|
||||
void setActive(bool yes) {active_ = yes;}
|
||||
void setDuplicatesEnabled(bool yes) {duplicates_ = yes;}
|
||||
void setActive(bool yes) { active_ = yes; }
|
||||
void setDuplicatesEnabled(bool yes) { duplicates_ = yes; }
|
||||
void setLimit(int l);
|
||||
void setHistoryColor(const QColor & c);
|
||||
void clear(bool silent);
|
||||
void clear() {clear(false);}
|
||||
void clear() { clear(false); }
|
||||
void undo();
|
||||
void redo();
|
||||
|
||||
|
||||
private slots:
|
||||
void itemClicked(QListWidgetItem * item);
|
||||
void itemSelectionChanged();
|
||||
|
||||
|
||||
signals:
|
||||
void undoAvailable(bool);
|
||||
void redoAvailable(bool);
|
||||
@@ -95,7 +96,6 @@ signals:
|
||||
void commandRequest(QByteArray & s);
|
||||
void commandExecute(const QByteArray & s);
|
||||
void changed();
|
||||
|
||||
};
|
||||
|
||||
#endif // HISTORYVIEW_H
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
#include "logview.h"
|
||||
#include "ui_logview.h"
|
||||
#include "qad_types.h"
|
||||
|
||||
#include "ecombobox.h"
|
||||
#include <QTextDocument>
|
||||
#include "qad_types.h"
|
||||
#include "ui_logview.h"
|
||||
|
||||
#include <QAbstractTextDocumentLayout>
|
||||
#include <QTextEdit>
|
||||
#include <QTextBlock>
|
||||
#include <QScrollBar>
|
||||
#include <QPixmap>
|
||||
#include <QEvent>
|
||||
#include <QPixmap>
|
||||
#include <QScrollBar>
|
||||
#include <QTextBlock>
|
||||
#include <QTextBlockUserData>
|
||||
#include <QTextDocument>
|
||||
#include <QTextEdit>
|
||||
|
||||
|
||||
class TextBlockData: public QTextBlockUserData {
|
||||
@@ -19,8 +21,6 @@ public:
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
LogView::Category::Category() {
|
||||
bold = false;
|
||||
}
|
||||
@@ -104,33 +104,45 @@ int LogView::linesLimit() const {
|
||||
}
|
||||
|
||||
|
||||
void LogView::registerCategory(const QString & label, QString keyword, const QImage & icon, QBrush text_brush, QBrush background, bool bold) {
|
||||
void LogView::registerCategory(const QString & label,
|
||||
QString keyword,
|
||||
const QImage & icon,
|
||||
QBrush text_brush,
|
||||
QBrush background,
|
||||
bool bold) {
|
||||
QRegularExpression regexp(keyword,
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
||||
QRegularExpression::PatternOptions(QRegularExpression::CaseInsensitiveOption)
|
||||
QRegularExpression::PatternOptions(QRegularExpression::CaseInsensitiveOption)
|
||||
#else
|
||||
Qt::CaseInsensitive
|
||||
Qt::CaseInsensitive
|
||||
#endif
|
||||
);
|
||||
);
|
||||
registerCategory(label, regexp, icon, text_brush, background, bold);
|
||||
}
|
||||
|
||||
|
||||
void LogView::registerCategory(const QString & label, QRegularExpression regexp, const QImage & icon, QBrush text_brush, QBrush background, bool bold) {
|
||||
void LogView::registerCategory(const QString & label,
|
||||
QRegularExpression regexp,
|
||||
const QImage & icon,
|
||||
QBrush text_brush,
|
||||
QBrush background,
|
||||
bool bold) {
|
||||
if (!regexp.isValid() || regexp.pattern().isEmpty()) return;
|
||||
removeCategory(regexp);
|
||||
Category c;
|
||||
c.regexp = regexp;
|
||||
c.label = label;
|
||||
c.image = icon;
|
||||
c.regexp = regexp;
|
||||
c.label = label;
|
||||
c.image = icon;
|
||||
c.text_brush = text_brush;
|
||||
c.background = background;
|
||||
c.bold = bold;
|
||||
c.makeIcon(iconImageSize(), preferredIconSize(1., this)
|
||||
c.bold = bold;
|
||||
c.makeIcon(iconImageSize(),
|
||||
preferredIconSize(1., this)
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
|
||||
, devicePixelRatioF()
|
||||
,
|
||||
devicePixelRatioF()
|
||||
#endif
|
||||
);
|
||||
);
|
||||
categories.append(c);
|
||||
ui->comboCategory->addItem(c.icon, label, QVariant(regexp));
|
||||
}
|
||||
@@ -139,11 +151,11 @@ void LogView::registerCategory(const QString & label, QRegularExpression regexp,
|
||||
void LogView::removeCategory(QString keyword) {
|
||||
QRegularExpression regexp(keyword,
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
||||
QRegularExpression::PatternOptions(QRegularExpression::CaseInsensitiveOption)
|
||||
QRegularExpression::PatternOptions(QRegularExpression::CaseInsensitiveOption)
|
||||
#else
|
||||
Qt::CaseInsensitive
|
||||
Qt::CaseInsensitive
|
||||
#endif
|
||||
);
|
||||
);
|
||||
removeCategory(regexp);
|
||||
}
|
||||
|
||||
@@ -153,13 +165,14 @@ void LogView::removeCategory(QRegularExpression regexp) {
|
||||
c.regexp = regexp;
|
||||
categories.removeAll(c);
|
||||
for (int i = 1; i < ui->comboCategory->count(); ++i) {
|
||||
if (ui->comboCategory->itemData(i).
|
||||
if (ui->comboCategory->itemData(i)
|
||||
.
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
||||
toRegularExpression()
|
||||
toRegularExpression()
|
||||
#else
|
||||
toRegExp()
|
||||
toRegExp()
|
||||
#endif
|
||||
.pattern() == regexp.pattern()) {
|
||||
.pattern() == regexp.pattern()) {
|
||||
ui->comboCategory->removeItem(i);
|
||||
--i;
|
||||
}
|
||||
@@ -188,16 +201,13 @@ void LogView::addText(const QString & text, const QString & keyword, bool insert
|
||||
QStringList sl = text.split("\n");
|
||||
tc.movePosition(QTextCursor::End);
|
||||
QScrollBar * bar = ui->textEdit->verticalScrollBar();
|
||||
bool at_end = (bar->value() == bar->maximum()) || bar->isHidden();
|
||||
bool at_end = (bar->value() == bar->maximum()) || bar->isHidden();
|
||||
for (int i = 0; i < sl.size(); ++i) {
|
||||
tc.insertText(sl[i]);
|
||||
if (!keyword.isEmpty())
|
||||
tc.block().setUserData(new TextBlockData(keyword));
|
||||
if ((i < sl.size() - 1) || insert_newline)
|
||||
newLine(keyword);
|
||||
if (!keyword.isEmpty()) tc.block().setUserData(new TextBlockData(keyword));
|
||||
if ((i < sl.size() - 1) || insert_newline) newLine(keyword);
|
||||
}
|
||||
if (at_end)
|
||||
scrollToBottom();
|
||||
if (at_end) scrollToBottom();
|
||||
}
|
||||
|
||||
|
||||
@@ -215,12 +225,14 @@ void LogView::changeEvent(QEvent * e) {
|
||||
ui->labelIconSearch->setFixedSize(preferredIconSize(1.2, this));
|
||||
QSize is = iconImageSize(), is_i = preferredIconSize(1., this);
|
||||
for (int i = 0; i < categories.size(); ++i)
|
||||
categories[i].makeIcon(is, is_i
|
||||
categories[i].makeIcon(is,
|
||||
is_i
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
|
||||
, devicePixelRatioF()
|
||||
,
|
||||
devicePixelRatioF()
|
||||
#endif
|
||||
);
|
||||
} break;
|
||||
);
|
||||
} break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
@@ -232,19 +244,18 @@ void LogView::newLine(const QString & keyword) {
|
||||
tc.movePosition(QTextCursor::StartOfBlock, QTextCursor::KeepAnchor);
|
||||
QString line = tc.selectedText();
|
||||
QImage icon;
|
||||
foreach (const Category & c, categories) {
|
||||
foreach(const Category & c, categories) {
|
||||
bool matched = false;
|
||||
if (keyword.isEmpty()) matched = line.contains(c.regexp);
|
||||
else matched = (keyword == c.regexp.pattern());
|
||||
if (keyword.isEmpty())
|
||||
matched = line.contains(c.regexp);
|
||||
else
|
||||
matched = (keyword == c.regexp.pattern());
|
||||
if (matched) {
|
||||
QTextCharFormat cf = def_cf;
|
||||
QTextCharFormat cf = def_cf;
|
||||
QTextBlockFormat bf = def_bf;
|
||||
if (c.text_brush != Qt::NoBrush)
|
||||
cf.setForeground(c.text_brush);
|
||||
if (c.background != Qt::NoBrush)
|
||||
bf.setBackground(c.background);
|
||||
if (c.bold)
|
||||
cf.setFontWeight(QFont::Bold);
|
||||
if (c.text_brush != Qt::NoBrush) cf.setForeground(c.text_brush);
|
||||
if (c.background != Qt::NoBrush) bf.setBackground(c.background);
|
||||
if (c.bold) cf.setFontWeight(QFont::Bold);
|
||||
tc.setCharFormat(cf);
|
||||
tc.setBlockFormat(bf);
|
||||
icon = c.icon_image;
|
||||
@@ -257,13 +268,12 @@ void LogView::newLine(const QString & keyword) {
|
||||
}
|
||||
QRegularExpression regexp =
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
||||
ui->comboCategory->currentData().toRegularExpression();
|
||||
ui->comboCategory->currentData().toRegularExpression();
|
||||
#else
|
||||
ui->comboCategory->itemData(ui->comboCategory->currentIndex()).toRegExp();
|
||||
ui->comboCategory->itemData(ui->comboCategory->currentIndex()).toRegExp();
|
||||
#endif
|
||||
QString fs = ui->lineEdit->text();
|
||||
if (isFilterVisible())
|
||||
filterBlock(tc.block(), fs, regexp);
|
||||
if (isFilterVisible()) filterBlock(tc.block(), fs, regexp);
|
||||
tc.movePosition(QTextCursor::End);
|
||||
tc.setCharFormat(def_cf);
|
||||
tc.insertBlock();
|
||||
@@ -278,15 +288,14 @@ QSize LogView::iconImageSize() {
|
||||
|
||||
|
||||
void LogView::filterBlock(QTextBlock block, const QString & fs, const QRegularExpression & regexp) {
|
||||
bool vis = true;//, pvis = block.isVisible();
|
||||
bool vis = true; //, pvis = block.isVisible();
|
||||
QString line = block.text();
|
||||
if (!line.isEmpty()) {
|
||||
if (line[0] == QChar::ObjectReplacementCharacter)
|
||||
line.remove(0, 1);
|
||||
if (line[0] == QChar::ObjectReplacementCharacter) line.remove(0, 1);
|
||||
}
|
||||
if (regexp.isValid() && !regexp.pattern().isEmpty()) {
|
||||
QString kw;
|
||||
TextBlockData * bd = (TextBlockData*)block.userData();
|
||||
TextBlockData * bd = (TextBlockData *)block.userData();
|
||||
if (bd) kw = bd->keyword;
|
||||
if (!kw.isEmpty())
|
||||
vis = vis && (bd->keyword == regexp.pattern());
|
||||
@@ -295,8 +304,8 @@ void LogView::filterBlock(QTextBlock block, const QString & fs, const QRegularEx
|
||||
}
|
||||
if (!fs.isEmpty()) vis = vis && line.contains(fs, Qt::CaseInsensitive);
|
||||
block.setVisible(vis);
|
||||
//qDebug() << "filterBlock" << line << vis;
|
||||
//if (vis != pvis)
|
||||
// qDebug() << "filterBlock" << line << vis;
|
||||
// if (vis != pvis)
|
||||
// ;//ui->textEdit->document()->mar
|
||||
}
|
||||
|
||||
@@ -325,16 +334,16 @@ void LogView::scrollToBottom() {
|
||||
|
||||
void LogView::filter() {
|
||||
QTextDocument * doc = ui->textEdit->document();
|
||||
int bc = doc->blockCount();
|
||||
int bc = doc->blockCount();
|
||||
QRegularExpression regexp;
|
||||
QString fs;
|
||||
if (isFilterVisible()) {
|
||||
regexp =
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
||||
ui->comboCategory->currentData().toRegularExpression();
|
||||
#else
|
||||
ui->comboCategory->itemData(ui->comboCategory->currentIndex()).toRegExp();
|
||||
#endif
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
||||
ui->comboCategory->currentData().toRegularExpression();
|
||||
#else
|
||||
ui->comboCategory->itemData(ui->comboCategory->currentIndex()).toRegExp();
|
||||
#endif
|
||||
fs = ui->lineEdit->text();
|
||||
}
|
||||
QTextBlock bl;
|
||||
|
||||
@@ -1,34 +1,34 @@
|
||||
/*
|
||||
QAD - Qt ADvanced
|
||||
QAD - Qt ADvanced
|
||||
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 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 Lesser General Public License for more details.
|
||||
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 Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef LOGVIEW_H
|
||||
#define LOGVIEW_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QIcon>
|
||||
#include <QImage>
|
||||
#include <QTextBlockFormat>
|
||||
#include <QWidget>
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
||||
# include <QRegularExpression>
|
||||
#else
|
||||
# include <QRegExp>
|
||||
typedef QRegExp QRegularExpression;
|
||||
typedef QRegExp QRegularExpression;
|
||||
#endif
|
||||
#include "qad_application_export.h"
|
||||
|
||||
@@ -37,19 +37,19 @@ class QTextBlock;
|
||||
class QAction;
|
||||
|
||||
namespace Ui {
|
||||
class LogView;
|
||||
class LogView;
|
||||
}
|
||||
|
||||
class QAD_APPLICATION_EXPORT LogView: public QWidget
|
||||
{
|
||||
class QAD_APPLICATION_EXPORT LogView: public QWidget {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool filterVisible READ isFilterVisible WRITE setFilterVisible)
|
||||
Q_PROPERTY(int linesLimit READ linesLimit WRITE setLinesLimit)
|
||||
Q_PROPERTY(QFont logFont READ logFont WRITE setLogFont)
|
||||
|
||||
public:
|
||||
explicit LogView(QWidget * parent = 0);
|
||||
~LogView();
|
||||
|
||||
|
||||
const QTextEdit * textEdit() const;
|
||||
void setLogFont(QFont f);
|
||||
QFont logFont() const;
|
||||
@@ -58,25 +58,25 @@ public:
|
||||
int linesLimit() const;
|
||||
|
||||
void registerCategory(const QString & label,
|
||||
QString keyword = QString(),
|
||||
const QImage & icon = QImage(),
|
||||
QBrush text_brush = Qt::NoBrush,
|
||||
QBrush background = Qt::NoBrush,
|
||||
bool bold = false);
|
||||
QString keyword = QString(),
|
||||
const QImage & icon = QImage(),
|
||||
QBrush text_brush = Qt::NoBrush,
|
||||
QBrush background = Qt::NoBrush,
|
||||
bool bold = false);
|
||||
|
||||
void registerCategory(const QString & label,
|
||||
QRegularExpression regexp,
|
||||
const QImage & icon = QImage(),
|
||||
QBrush text_brush = Qt::NoBrush,
|
||||
QBrush background = Qt::NoBrush,
|
||||
bool bold = false);
|
||||
QRegularExpression regexp,
|
||||
const QImage & icon = QImage(),
|
||||
QBrush text_brush = Qt::NoBrush,
|
||||
QBrush background = Qt::NoBrush,
|
||||
bool bold = false);
|
||||
void removeCategory(QString keyword);
|
||||
void removeCategory(QRegularExpression regexp);
|
||||
void clearCategories();
|
||||
|
||||
void addText(const QString & text, bool insert_newline = true);
|
||||
void addText(const QString & text, const QString & keyword, bool insert_newline = true);
|
||||
|
||||
|
||||
private:
|
||||
struct QAD_APPLICATION_EXPORT Category {
|
||||
Category();
|
||||
@@ -88,31 +88,30 @@ private:
|
||||
QBrush text_brush;
|
||||
QBrush background;
|
||||
bool bold;
|
||||
inline bool operator ==(const Category & it) const {return (regexp.pattern() == it.regexp.pattern());}
|
||||
inline bool operator==(const Category & it) const { return (regexp.pattern() == it.regexp.pattern()); }
|
||||
};
|
||||
|
||||
|
||||
void changeEvent(QEvent * e);
|
||||
void newLine(const QString & keyword);
|
||||
QSize iconImageSize();
|
||||
void filterBlock(QTextBlock block, const QString & fs, const QRegularExpression & regexp);
|
||||
|
||||
|
||||
Ui::LogView * ui;
|
||||
QList<Category> categories;
|
||||
QTextCharFormat def_cf;
|
||||
QTextBlockFormat def_bf;
|
||||
QAction * actionLogSelectAll, * actionLogCopy, * actionLogClear;
|
||||
QAction *actionLogSelectAll, *actionLogCopy, *actionLogClear;
|
||||
|
||||
public slots:
|
||||
void setFilterVisible(bool yes);
|
||||
void setLinesLimit(int l);
|
||||
void clear();
|
||||
|
||||
|
||||
private slots:
|
||||
void scrollToBottom();
|
||||
void filter();
|
||||
|
||||
|
||||
signals:
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "edockwidget.h"
|
||||
#include "edockwidgetplugin.h"
|
||||
|
||||
#include "edockwidget.h"
|
||||
|
||||
#include <QtCore/QtPlugin>
|
||||
|
||||
|
||||
@@ -9,8 +11,7 @@ EDockWidgetPlugin::EDockWidgetPlugin(QObject * parent): QObject(parent) {
|
||||
|
||||
|
||||
void EDockWidgetPlugin::initialize(QDesignerFormEditorInterface * /* core */) {
|
||||
if (m_initialized)
|
||||
return;
|
||||
if (m_initialized) return;
|
||||
|
||||
// Add extension registrations, etc. here
|
||||
|
||||
@@ -66,4 +67,3 @@ QString EDockWidgetPlugin::domXml() const {
|
||||
QString EDockWidgetPlugin::includeFile() const {
|
||||
return QLatin1String("edockwidget.h");
|
||||
}
|
||||
|
||||
|
||||
@@ -8,8 +8,9 @@
|
||||
# include <QDesignerCustomWidgetInterface>
|
||||
#endif
|
||||
|
||||
class EDockWidgetPlugin: public QObject, public QDesignerCustomWidgetInterface
|
||||
{
|
||||
class EDockWidgetPlugin
|
||||
: public QObject
|
||||
, public QDesignerCustomWidgetInterface {
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(QDesignerCustomWidgetInterface)
|
||||
|
||||
@@ -30,7 +31,6 @@ public:
|
||||
|
||||
private:
|
||||
bool m_initialized;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "emainwindow.h"
|
||||
#include "emainwindowplugin.h"
|
||||
|
||||
#include "emainwindow.h"
|
||||
|
||||
#include <QtCore/QtPlugin>
|
||||
|
||||
|
||||
@@ -9,8 +11,7 @@ EMainWindowPlugin::EMainWindowPlugin(QObject * parent): QObject(parent) {
|
||||
|
||||
|
||||
void EMainWindowPlugin::initialize(QDesignerFormEditorInterface * /* core */) {
|
||||
if (m_initialized)
|
||||
return;
|
||||
if (m_initialized) return;
|
||||
|
||||
// Add extension registrations, etc. here
|
||||
|
||||
@@ -66,4 +67,3 @@ QString EMainWindowPlugin::domXml() const {
|
||||
QString EMainWindowPlugin::includeFile() const {
|
||||
return QLatin1String("emainwindow.h");
|
||||
}
|
||||
|
||||
|
||||
@@ -8,8 +8,9 @@
|
||||
# include <QDesignerCustomWidgetInterface>
|
||||
#endif
|
||||
|
||||
class EMainWindowPlugin: public QObject, public QDesignerCustomWidgetInterface
|
||||
{
|
||||
class EMainWindowPlugin
|
||||
: public QObject
|
||||
, public QDesignerCustomWidgetInterface {
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(QDesignerCustomWidgetInterface)
|
||||
|
||||
@@ -30,7 +31,6 @@ public:
|
||||
|
||||
private:
|
||||
bool m_initialized;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "historyview.h"
|
||||
#include "historyviewplugin.h"
|
||||
|
||||
#include "historyview.h"
|
||||
|
||||
#include <QtCore/QtPlugin>
|
||||
|
||||
|
||||
@@ -9,8 +11,7 @@ HistoryViewPlugin::HistoryViewPlugin(QObject * parent): QObject(parent) {
|
||||
|
||||
|
||||
void HistoryViewPlugin::initialize(QDesignerFormEditorInterface * /* core */) {
|
||||
if (m_initialized)
|
||||
return;
|
||||
if (m_initialized) return;
|
||||
|
||||
// Add extension registrations, etc. here
|
||||
|
||||
@@ -66,4 +67,3 @@ QString HistoryViewPlugin::domXml() const {
|
||||
QString HistoryViewPlugin::includeFile() const {
|
||||
return QLatin1String("historyview.h");
|
||||
}
|
||||
|
||||
|
||||
@@ -8,8 +8,9 @@
|
||||
# include <QDesignerCustomWidgetInterface>
|
||||
#endif
|
||||
|
||||
class HistoryViewPlugin: public QObject, public QDesignerCustomWidgetInterface
|
||||
{
|
||||
class HistoryViewPlugin
|
||||
: public QObject
|
||||
, public QDesignerCustomWidgetInterface {
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(QDesignerCustomWidgetInterface)
|
||||
|
||||
@@ -30,7 +31,6 @@ public:
|
||||
|
||||
private:
|
||||
bool m_initialized;
|
||||
|
||||
};
|
||||
|
||||
#endif // HISTORYVIEWPLUGIN_H
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "logview.h"
|
||||
#include "logviewplugin.h"
|
||||
|
||||
#include "logview.h"
|
||||
|
||||
#include <QtCore/QtPlugin>
|
||||
|
||||
|
||||
@@ -9,8 +11,7 @@ LogViewPlugin::LogViewPlugin(QObject * parent): QObject(parent) {
|
||||
|
||||
|
||||
void LogViewPlugin::initialize(QDesignerFormEditorInterface * /* core */) {
|
||||
if (m_initialized)
|
||||
return;
|
||||
if (m_initialized) return;
|
||||
|
||||
// Add extension registrations, etc. here
|
||||
|
||||
@@ -66,4 +67,3 @@ QString LogViewPlugin::domXml() const {
|
||||
QString LogViewPlugin::includeFile() const {
|
||||
return QLatin1String("logview.h");
|
||||
}
|
||||
|
||||
|
||||
@@ -8,8 +8,9 @@
|
||||
# include <QDesignerCustomWidgetInterface>
|
||||
#endif
|
||||
|
||||
class LogViewPlugin: public QObject, public QDesignerCustomWidgetInterface
|
||||
{
|
||||
class LogViewPlugin
|
||||
: public QObject
|
||||
, public QDesignerCustomWidgetInterface {
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(QDesignerCustomWidgetInterface)
|
||||
|
||||
@@ -30,7 +31,6 @@ public:
|
||||
|
||||
private:
|
||||
bool m_initialized;
|
||||
|
||||
};
|
||||
|
||||
#endif // LOGVIEWPLUGIN_H
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "qad_application.h"
|
||||
|
||||
#include "edockwidgetplugin.h"
|
||||
#include "emainwindowplugin.h"
|
||||
#include "historyviewplugin.h"
|
||||
@@ -6,14 +7,14 @@
|
||||
|
||||
|
||||
QADApplication::QADApplication(QObject * parent): QObject(parent) {
|
||||
//m_widgets.append(new EDockWidgetPlugin(this));
|
||||
// m_widgets.append(new EDockWidgetPlugin(this));
|
||||
m_widgets.append(new EMainWindowPlugin(this));
|
||||
m_widgets.append(new HistoryViewPlugin(this));
|
||||
m_widgets.append(new LogViewPlugin(this));
|
||||
}
|
||||
|
||||
|
||||
QList<QDesignerCustomWidgetInterface * > QADApplication::customWidgets() const {
|
||||
QList<QDesignerCustomWidgetInterface *> QADApplication::customWidgets() const {
|
||||
return m_widgets;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,23 +1,24 @@
|
||||
#ifndef QAD_APPLICATION_H
|
||||
#define QAD_APPLICATION_H
|
||||
|
||||
#include <QtDesigner/QtDesigner>
|
||||
#include <QtCore/qplugin.h>
|
||||
#include <QtDesigner/QtDesigner>
|
||||
|
||||
class QADApplication: public QObject, public QDesignerCustomWidgetCollectionInterface
|
||||
{
|
||||
class QADApplication
|
||||
: public QObject
|
||||
, public QDesignerCustomWidgetCollectionInterface {
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(QDesignerCustomWidgetCollectionInterface)
|
||||
#if QT_VERSION >= 0x050000
|
||||
Q_PLUGIN_METADATA(IID "qad.application")
|
||||
#endif
|
||||
|
||||
public:
|
||||
explicit QADApplication(QObject * parent = 0);
|
||||
virtual QList<QDesignerCustomWidgetInterface * > customWidgets() const;
|
||||
virtual QList<QDesignerCustomWidgetInterface *> customWidgets() const;
|
||||
|
||||
private:
|
||||
QList<QDesignerCustomWidgetInterface * > m_widgets;
|
||||
|
||||
QList<QDesignerCustomWidgetInterface *> m_widgets;
|
||||
};
|
||||
|
||||
#endif // QAD_APPLICATION_H
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <QDebug>
|
||||
#include "qsingleapplication.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
#define QSA_SHMSIZE 4096
|
||||
#define QSA_MSGSIZE (QSA_SHMSIZE - sizeof(quint32) - sizeof(quint32))
|
||||
@@ -9,12 +10,11 @@
|
||||
QSingleApplication::QSingleApplication(const QString & app_name): QThread() {
|
||||
shm.setKey(app_name);
|
||||
exiting = false;
|
||||
first = !shm.attach();
|
||||
first = !shm.attach();
|
||||
if (!first) {
|
||||
shm.detach();
|
||||
first = !shm.attach();
|
||||
if (!first)
|
||||
return;
|
||||
if (!first) return;
|
||||
}
|
||||
shm.create(QSA_SHMSIZE);
|
||||
shm.attach();
|
||||
@@ -23,7 +23,7 @@ QSingleApplication::QSingleApplication(const QString & app_name): QThread() {
|
||||
if (d) memset(d, 0, sizeof(quint32));
|
||||
shm.unlock();
|
||||
start();
|
||||
//qDebug() << "start listen";
|
||||
// qDebug() << "start listen";
|
||||
}
|
||||
|
||||
|
||||
@@ -31,15 +31,14 @@ QSingleApplication::~QSingleApplication() {
|
||||
if (first) {
|
||||
exiting = true;
|
||||
quit();
|
||||
if (!wait(100))
|
||||
terminate();
|
||||
if (!wait(100)) terminate();
|
||||
}
|
||||
if (shm.isAttached()) shm.detach();
|
||||
}
|
||||
|
||||
|
||||
void QSingleApplication::sendMessage(const QByteArray & m) {
|
||||
//qDebug() << "send message" << first << shm.isAttached();
|
||||
// qDebug() << "send message" << first << shm.isAttached();
|
||||
if (first || !shm.isAttached()) return;
|
||||
if (m.size() > int(QSA_MSGSIZE)) {
|
||||
qDebug() << "[QSingleApplication] Too large message:" << m.size() << ">" << QSA_MSGSIZE;
|
||||
@@ -52,8 +51,8 @@ void QSingleApplication::sendMessage(const QByteArray & m) {
|
||||
memcpy(&num, d, sizeof(quint32));
|
||||
num++;
|
||||
memcpy(d, &num, sizeof(quint32));
|
||||
memcpy((((char*)d) + sizeof(quint32)), &size, sizeof(quint32));
|
||||
memcpy((((char*)d) + sizeof(quint32) + sizeof(quint32)), m.constData(), size);
|
||||
memcpy((((char *)d) + sizeof(quint32)), &size, sizeof(quint32));
|
||||
memcpy((((char *)d) + sizeof(quint32) + sizeof(quint32)), m.constData(), size);
|
||||
}
|
||||
shm.unlock();
|
||||
}
|
||||
@@ -68,12 +67,12 @@ void QSingleApplication::run() {
|
||||
memcpy(&num, d, sizeof(quint32));
|
||||
if (pnum != num) {
|
||||
pnum = num;
|
||||
//qDebug() << "new message" << num;
|
||||
memcpy(&size, (((const char*)d) + sizeof(quint32)), sizeof(quint32));
|
||||
// qDebug() << "new message" << num;
|
||||
memcpy(&size, (((const char *)d) + sizeof(quint32)), sizeof(quint32));
|
||||
if (size <= int(QSA_MSGSIZE)) {
|
||||
QByteArray msg;
|
||||
msg.resize(size);
|
||||
memcpy(msg.data(), (((const char*)d) + sizeof(quint32) + sizeof(quint32)), size);
|
||||
memcpy(msg.data(), (((const char *)d) + sizeof(quint32) + sizeof(quint32)), size);
|
||||
emit messageReceived(msg);
|
||||
} else {
|
||||
qDebug() << "[QSingleApplication] Invalid message size:" << size;
|
||||
|
||||
@@ -1,51 +1,51 @@
|
||||
/*
|
||||
QAD - Qt ADvanced
|
||||
QAD - Qt ADvanced
|
||||
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 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 Lesser General Public License for more details.
|
||||
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 Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef QSINGLEAPPLICATION_H
|
||||
#define QSINGLEAPPLICATION_H
|
||||
|
||||
#include <QThread>
|
||||
#include <QSharedMemory>
|
||||
#include "qad_application_export.h"
|
||||
|
||||
#include <QSharedMemory>
|
||||
#include <QThread>
|
||||
|
||||
class QAD_APPLICATION_EXPORT QSingleApplication: public QThread
|
||||
{
|
||||
|
||||
class QAD_APPLICATION_EXPORT QSingleApplication: public QThread {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QSingleApplication(const QString & app_name = QString("qapp"));
|
||||
~QSingleApplication();
|
||||
|
||||
bool isFirst() const {return first;}
|
||||
|
||||
|
||||
bool isFirst() const { return first; }
|
||||
|
||||
private:
|
||||
void run();
|
||||
|
||||
|
||||
QSharedMemory shm;
|
||||
bool first, exiting;
|
||||
|
||||
|
||||
public slots:
|
||||
void sendMessage(const QByteArray & m);
|
||||
|
||||
|
||||
signals:
|
||||
void messageReceived(QByteArray);
|
||||
|
||||
};
|
||||
|
||||
#endif // QSINGLEAPPLICATION_H
|
||||
|
||||
@@ -1,49 +1,45 @@
|
||||
#include "ribbon.h"
|
||||
|
||||
#include "qad_types.h"
|
||||
|
||||
#include <QScrollBar>
|
||||
|
||||
|
||||
Ribbon::Ribbon(QMainWindow * parent_): QToolBar() {
|
||||
tab = 0;
|
||||
tab = 0;
|
||||
scroll_area = 0;
|
||||
delay_e = true;
|
||||
delay = 1000;
|
||||
hovered = -1;
|
||||
delay_e = true;
|
||||
delay = 1000;
|
||||
hovered = -1;
|
||||
setObjectName("ribbon");
|
||||
setProperty("ribbon", true);
|
||||
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
||||
parent = parent_;
|
||||
if (parent_)
|
||||
parent_->installEventFilter(this);
|
||||
if (parent_) parent_->installEventFilter(this);
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
Ribbon::~Ribbon() {
|
||||
}
|
||||
Ribbon::~Ribbon() {}
|
||||
|
||||
|
||||
bool Ribbon::eventFilter(QObject * o, QEvent * e) {
|
||||
//qDebug() << e;
|
||||
// qDebug() << e;
|
||||
if (o == parent) {
|
||||
if (e->type() == QEvent::Resize || e->type() == QEvent::WindowActivate)
|
||||
_resize();
|
||||
if (e->type() == QEvent::FontChange || e->type() == QEvent::Polish)
|
||||
_setIconsSize();
|
||||
if (e->type() == QEvent::Resize || e->type() == QEvent::WindowActivate) _resize();
|
||||
if (e->type() == QEvent::FontChange || e->type() == QEvent::Polish) _setIconsSize();
|
||||
return QToolBar::eventFilter(o, e);
|
||||
}
|
||||
if (e->type() == QEvent::ActionChanged) {
|
||||
QToolButton * b = qobject_cast<QToolButton * >((QObject * )o->property("ribbonButton").toLongLong());
|
||||
if (b != 0)
|
||||
b->setEnabled(qobject_cast<QAction * >(o)->isEnabled());
|
||||
QToolButton * b = qobject_cast<QToolButton *>((QObject *)o->property("ribbonButton").toLongLong());
|
||||
if (b != 0) b->setEnabled(qobject_cast<QAction *>(o)->isEnabled());
|
||||
}
|
||||
return QToolBar::eventFilter(o, e);
|
||||
}
|
||||
|
||||
|
||||
void Ribbon::timerEvent(QTimerEvent * e) {
|
||||
if (hovers.value(e->timerId(), -1) == hovered)
|
||||
tab->setCurrentIndex(hovered);
|
||||
if (hovers.value(e->timerId(), -1) == hovered) tab->setCurrentIndex(hovered);
|
||||
hovers.remove(e->timerId());
|
||||
killTimer(e->timerId());
|
||||
}
|
||||
@@ -52,11 +48,8 @@ void Ribbon::timerEvent(QTimerEvent * e) {
|
||||
void Ribbon::changeEvent(QEvent * e) {
|
||||
QToolBar::changeEvent(e);
|
||||
switch (e->type()) {
|
||||
case QEvent::LanguageChange:
|
||||
retranslate();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case QEvent::LanguageChange: retranslate(); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,16 +57,16 @@ void Ribbon::changeEvent(QEvent * e) {
|
||||
void Ribbon::_resize() {
|
||||
return; // WARNING
|
||||
for (int i = 0; i < tab->count(); ++i) {
|
||||
int h = ((QScrollArea*)(tab->widget(i)))->sizeHint().height();
|
||||
if (((QScrollArea*)(tab->widget(i)))->horizontalScrollBar()->isVisible())
|
||||
h += ((QScrollArea*)(tab->widget(i)))->horizontalScrollBar()->height();
|
||||
((QScrollArea*)(tab->widget(i)))->setMinimumHeight(h);
|
||||
int h = ((QScrollArea *)(tab->widget(i)))->sizeHint().height();
|
||||
if (((QScrollArea *)(tab->widget(i)))->horizontalScrollBar()->isVisible())
|
||||
h += ((QScrollArea *)(tab->widget(i)))->horizontalScrollBar()->height();
|
||||
((QScrollArea *)(tab->widget(i)))->setMinimumHeight(h);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Ribbon::_setIconsSize() {
|
||||
//qDebug() << "resize" << preferredIconSize() << QApplication::font();
|
||||
// qDebug() << "resize" << preferredIconSize() << QApplication::font();
|
||||
setTabIconSize(preferredIconSize(2, this));
|
||||
setIconSize(preferredIconSize(3, this));
|
||||
}
|
||||
@@ -86,7 +79,6 @@ void Ribbon::_setButtonText(QToolButton * b, QAction * a) {
|
||||
sc += "\n" + s.toString(QKeySequence::NativeText);
|
||||
}
|
||||
b->setToolTip(a->text() + sc);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -101,11 +93,10 @@ void Ribbon::setVisible(bool yes) {
|
||||
void Ribbon::init() {
|
||||
if (parent == 0) return;
|
||||
if (parent->menuBar() == 0) return;
|
||||
QList<QAction * > lm = parent->menuBar()->actions(), la;
|
||||
QList<QAction *> lm = parent->menuBar()->actions(), la;
|
||||
QString prev_tab;
|
||||
if (tab) {
|
||||
if (tab->currentIndex() >= 0)
|
||||
prev_tab = tab->tabText(tab->currentIndex());
|
||||
if (tab->currentIndex() >= 0) prev_tab = tab->tabText(tab->currentIndex());
|
||||
tab->deleteLater();
|
||||
}
|
||||
clear();
|
||||
@@ -117,24 +108,24 @@ void Ribbon::init() {
|
||||
connect(tab, SIGNAL(currentChanged(int)), this, SIGNAL(currentTabChanged(int)));
|
||||
tab->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
QFrame * g;
|
||||
QBoxLayout * l, * tl;
|
||||
QBoxLayout *l, *tl;
|
||||
QToolButton * b;
|
||||
//tab->setIconSize(QSize(32, 32));
|
||||
// tab->setIconSize(QSize(32, 32));
|
||||
for (QAction * i: lm) {
|
||||
if (!i->menu()) continue;
|
||||
//if (!i->menu()->isVisible()) continue;
|
||||
la = i->menu()->actions();
|
||||
// if (!i->menu()->isVisible()) continue;
|
||||
la = i->menu()->actions();
|
||||
QIcon tic = i->icon();
|
||||
if (!tic.isNull())
|
||||
i->setProperty("__icon", QVariant::fromValue<QIcon>(tic));
|
||||
else
|
||||
tic = i->property("__icon").value<QIcon>();
|
||||
//#ifdef Q_OS_MACOS
|
||||
// tic = QIcon();
|
||||
//#endif
|
||||
// #ifdef Q_OS_MACOS
|
||||
// tic = QIcon();
|
||||
// #endif
|
||||
tab->addTab(new QWidget(), tic, i->text());
|
||||
//qDebug() << this << i->icon() << i->text();
|
||||
//continue;
|
||||
// qDebug() << this << i->icon() << i->text();
|
||||
// continue;
|
||||
/*QScrollArea * sa = new QScrollArea();
|
||||
sa->setWidget(new QWidget());
|
||||
sa->setWidgetResizable(true);
|
||||
@@ -143,7 +134,7 @@ void Ribbon::init() {
|
||||
sa->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||
sa->setFrameShape(QFrame::NoFrame);
|
||||
tab->addTab(sa, i->icon(), i->text());*/
|
||||
tab->widget(tab->count() - 1)->setProperty("ribbonAction", qlonglong((void * )i));
|
||||
tab->widget(tab->count() - 1)->setProperty("ribbonAction", qlonglong((void *)i));
|
||||
i->setIcon(QIcon());
|
||||
tl = new QBoxLayout(QBoxLayout::LeftToRight);
|
||||
tl->setSpacing(2);
|
||||
@@ -152,7 +143,8 @@ void Ribbon::init() {
|
||||
#else
|
||||
tl->setContentsMargins(2, 0, 2, 2);
|
||||
#endif
|
||||
g = new QFrame(); g->setFrameShape(QFrame::StyledPanel);
|
||||
g = new QFrame();
|
||||
g->setFrameShape(QFrame::StyledPanel);
|
||||
l = new QBoxLayout(QBoxLayout::LeftToRight);
|
||||
g->setLayout(l);
|
||||
l->setSpacing(2);
|
||||
@@ -161,24 +153,25 @@ void Ribbon::init() {
|
||||
if (j->isSeparator()) {
|
||||
if (l->isEmpty()) continue;
|
||||
tl->addWidget(g);
|
||||
g = new QFrame(); g->setFrameShape(QFrame::StyledPanel);
|
||||
g = new QFrame();
|
||||
g->setFrameShape(QFrame::StyledPanel);
|
||||
l = new QBoxLayout(QBoxLayout::LeftToRight);
|
||||
l->setSpacing(2);
|
||||
l->setContentsMargins(2, 2, 2, 2);
|
||||
g->setLayout(l);
|
||||
continue;
|
||||
}
|
||||
if (qobject_cast<QWidgetAction*>(j)) {
|
||||
QWidget * _w = qobject_cast<QWidgetAction*>(j)->defaultWidget();
|
||||
if (qobject_cast<QWidgetAction *>(j)) {
|
||||
QWidget * _w = qobject_cast<QWidgetAction *>(j)->defaultWidget();
|
||||
l->addWidget(_w);
|
||||
_w->show();
|
||||
continue;
|
||||
}
|
||||
b = new QToolButton();
|
||||
//b->setVisible(j->isVisible());
|
||||
// b->setVisible(j->isVisible());
|
||||
b->setEnabled(j->isEnabled());
|
||||
b->setProperty("ribbonAction", qlonglong((void * )j));
|
||||
j->setProperty("ribbonButton", qlonglong((void * )b));
|
||||
b->setProperty("ribbonAction", qlonglong((void *)j));
|
||||
j->setProperty("ribbonButton", qlonglong((void *)b));
|
||||
j->installEventFilter(this);
|
||||
if (j->menu() != 0) {
|
||||
b->setPopupMode(QToolButton::InstantPopup);
|
||||
@@ -193,11 +186,11 @@ void Ribbon::init() {
|
||||
} else
|
||||
connect(b, SIGNAL(clicked()), j, SLOT(trigger()));
|
||||
}
|
||||
//b->setIconSize(QSize(16, 16));
|
||||
// b->setIconSize(QSize(16, 16));
|
||||
b->setIcon(j->icon());
|
||||
_setButtonText(b, j);
|
||||
//b->addAction(j);
|
||||
//b->setShortcut(j->shortcut());
|
||||
// b->addAction(j);
|
||||
// b->setShortcut(j->shortcut());
|
||||
b->setAutoRaise(true);
|
||||
b->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
|
||||
b->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
|
||||
@@ -206,10 +199,9 @@ void Ribbon::init() {
|
||||
}
|
||||
tl->addWidget(g);
|
||||
tl->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Fixed));
|
||||
//sa->widget()->setLayout(tl);
|
||||
// sa->widget()->setLayout(tl);
|
||||
tab->widget(tab->count() - 1)->setLayout(tl);
|
||||
if (i->text() == prev_tab)
|
||||
tab->setCurrentIndex(tab->count() - 1);
|
||||
if (i->text() == prev_tab) tab->setCurrentIndex(tab->count() - 1);
|
||||
}
|
||||
setFloatable(false);
|
||||
setMovable(false);
|
||||
@@ -219,7 +211,7 @@ void Ribbon::init() {
|
||||
scroll_area->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||
scroll_area->setWidget(tab);*/
|
||||
_resize();
|
||||
//addWidget(scroll_area);
|
||||
// addWidget(scroll_area);
|
||||
addWidget(tab);
|
||||
parent->addToolBar(Qt::TopToolBarArea, this);
|
||||
parent->menuBar()->hide();
|
||||
@@ -231,13 +223,13 @@ void Ribbon::init() {
|
||||
void Ribbon::retranslate() {
|
||||
QAction * a;
|
||||
for (QToolButton * i: buttons) {
|
||||
a = (QAction * )(i->property("ribbonAction").toLongLong());
|
||||
a = (QAction *)(i->property("ribbonAction").toLongLong());
|
||||
if (a == 0) continue;
|
||||
_setButtonText(i, a);
|
||||
//i->setShortcut(a->shortcut());
|
||||
// i->setShortcut(a->shortcut());
|
||||
}
|
||||
for (int i = 0; i < tab->count(); ++i) {
|
||||
a = (QAction * )(tab->widget(i)->property("ribbonAction").toLongLong());
|
||||
a = (QAction *)(tab->widget(i)->property("ribbonAction").toLongLong());
|
||||
if (a == 0) continue;
|
||||
tab->setTabText(i, a->text());
|
||||
}
|
||||
|
||||
@@ -1,42 +1,43 @@
|
||||
/*
|
||||
QAD - Qt ADvanced
|
||||
QAD - Qt ADvanced
|
||||
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 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 Lesser General Public License for more details.
|
||||
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 Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef RIBBON_H
|
||||
#define RIBBON_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QActionGroup>
|
||||
#include <QWidgetAction>
|
||||
#include <QMenuBar>
|
||||
#include <QTabWidget>
|
||||
#include <QGroupBox>
|
||||
#include <QDockWidget>
|
||||
#include <QToolBar>
|
||||
#include <QToolButton>
|
||||
#include <QScrollArea>
|
||||
#include "etabwidget.h"
|
||||
#include "qad_application_export.h"
|
||||
|
||||
#include <QActionGroup>
|
||||
#include <QDockWidget>
|
||||
#include <QGroupBox>
|
||||
#include <QMainWindow>
|
||||
#include <QMenuBar>
|
||||
#include <QScrollArea>
|
||||
#include <QTabWidget>
|
||||
#include <QToolBar>
|
||||
#include <QToolButton>
|
||||
#include <QWidgetAction>
|
||||
|
||||
class QAD_APPLICATION_EXPORT Ribbon: public QToolBar
|
||||
{
|
||||
|
||||
class QAD_APPLICATION_EXPORT Ribbon: public QToolBar {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit Ribbon(QMainWindow * parent = 0);
|
||||
~Ribbon();
|
||||
@@ -45,41 +46,51 @@ public:
|
||||
void retranslate();
|
||||
void setIconSize(const QSize & size);
|
||||
void setTabIconSize(const QSize & size);
|
||||
void setButtonStyle(const Qt::ToolButtonStyle & style) {foreach (QToolButton * i, buttons) i->setToolButtonStyle(style);}
|
||||
void setAutoSwitchEnabled(bool yes) {delay_e = yes;}
|
||||
void setAutoSwitchDelay(float delay_s) {delay = delay_s * 1000;}
|
||||
void setCurrentTab(int tab_) {if (tab_ < 0 || tab_ >= tab->count()) return; tab->setCurrentIndex(tab_);}
|
||||
int currentTab() const {return tab->currentIndex();}
|
||||
QTabWidget * tabWidget() const {return tab;}
|
||||
void setButtonStyle(const Qt::ToolButtonStyle & style) {
|
||||
foreach(QToolButton * i, buttons)
|
||||
i->setToolButtonStyle(style);
|
||||
}
|
||||
void setAutoSwitchEnabled(bool yes) { delay_e = yes; }
|
||||
void setAutoSwitchDelay(float delay_s) { delay = delay_s * 1000; }
|
||||
void setCurrentTab(int tab_) {
|
||||
if (tab_ < 0 || tab_ >= tab->count()) return;
|
||||
tab->setCurrentIndex(tab_);
|
||||
}
|
||||
int currentTab() const { return tab->currentIndex(); }
|
||||
QTabWidget * tabWidget() const { return tab; }
|
||||
|
||||
private:
|
||||
bool eventFilter(QObject * o, QEvent * e);
|
||||
void timerEvent(QTimerEvent * e);
|
||||
void changeEvent(QEvent *e);
|
||||
void changeEvent(QEvent * e);
|
||||
void _resize();
|
||||
void _setIconsSize();
|
||||
void _setButtonText(QToolButton * b, QAction * a);
|
||||
|
||||
int hovered, delay;
|
||||
bool delay_e;
|
||||
QList<QToolButton * > buttons;
|
||||
QList<QToolButton *> buttons;
|
||||
QMap<int, int> hovers;
|
||||
ETabWidget * tab;
|
||||
QScrollArea * scroll_area;
|
||||
QMainWindow * parent;
|
||||
|
||||
private slots:
|
||||
void tabHovered(int tab) {if (!delay_e) return; hovers.clear(); hovered = tab; hovers.insert(startTimer(delay), tab);}
|
||||
|
||||
void tabHovered(int tab) {
|
||||
if (!delay_e) return;
|
||||
hovers.clear();
|
||||
hovered = tab;
|
||||
hovers.insert(startTimer(delay), tab);
|
||||
}
|
||||
|
||||
public slots:
|
||||
void setVisible(bool yes);
|
||||
void setHidden(bool yes) {setVisible(!yes);}
|
||||
void show() {setVisible(true);}
|
||||
void hide() {setVisible(false);}
|
||||
|
||||
void setHidden(bool yes) { setVisible(!yes); }
|
||||
void show() { setVisible(true); }
|
||||
void hide() { setVisible(false); }
|
||||
|
||||
signals:
|
||||
void currentTabChanged(int);
|
||||
|
||||
};
|
||||
|
||||
#endif // RIBBON_H
|
||||
|
||||
Reference in New Issue
Block a user