Commit ef912608 authored by Julien Wintz's avatar Julien Wintz
Browse files

Reverting deprecated classes in gui support layer.

parent e682d1b5
......@@ -34,8 +34,12 @@ set(${PROJECT_NAME}_HEADERS
dtkPluginsEditor.h
dtkPopup.h
dtkProgressIndicator.h
dtkRecentFilesMenu.h
dtkScreenMenu.h
dtkSearchField.h
dtkSettingsEditor.h
dtkSpacer.h
dtkSplitter.h
dtkSwitch.h
dtkTagCloud.h
dtkViewManager.h
......@@ -61,7 +65,11 @@ set(${PROJECT_NAME}_SOURCES
dtkPluginsEditor.cpp
dtkPopup.cpp
dtkProgressIndicator.cpp
dtkRecentFilesMenu.cpp
dtkScreenMenu.cpp
dtkSettingsEditor.cpp
dtkSpacer.cpp
dtkSplitter.cpp
dtkSwitch.cpp
dtkTagCloud.cpp
dtkViewManager.cpp
......
#include "dtkRecentFilesMenu.h"
\ No newline at end of file
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#include "dtkRecentFilesMenu.h"
#include <QtCore>
dtkRecentFilesMenu::dtkRecentFilesMenu(QWidget *parent) : QMenu(parent), m_maxCount(8)
{
connect(this, SIGNAL(triggered(QAction*)), this, SLOT(menuTriggered(QAction*)));
setMaxCount(m_maxCount);
}
dtkRecentFilesMenu::dtkRecentFilesMenu(const QString &title, QWidget *parent) : QMenu(title, parent), m_maxCount(8)
{
connect(this, SIGNAL(triggered(QAction*)), this, SLOT(menuTriggered(QAction*)));
setMaxCount(m_maxCount);
}
void dtkRecentFilesMenu::addRecentFile(const QString &fileName)
{
QSettings settings;
QStringList files = settings.value("recentFileList").toStringList();
files.removeAll(fileName);
files.prepend(fileName);
while (files.size() > maxCount())
files.removeLast();
settings.setValue("recentFileList", files);
updateRecentFileActions();
}
void dtkRecentFilesMenu::clearMenu(void)
{
QSettings settings;
settings.remove("recentFileList");
updateRecentFileActions();
}
int dtkRecentFilesMenu::maxCount(void) const
{
return m_maxCount;
}
void dtkRecentFilesMenu::setMaxCount(int count)
{
m_maxCount = count;
updateRecentFileActions();
}
void dtkRecentFilesMenu::menuTriggered(QAction* action)
{
if (action->data().isValid())
emit recentFileTriggered(action->data().toString());
}
void dtkRecentFilesMenu::updateRecentFileActions(void)
{
QSettings settings;
QStringList files = settings.value("recentFileList").toStringList();
int numRecentFiles = qMin(files.size(), maxCount());
clear();
for (int i = 0; i < numRecentFiles; ++i) {
QString strippedName = QFileInfo(files[i]).fileName();
QString text = QString("%1").arg(strippedName);
QAction* recentFileAct = addAction(text);
if(i+1 == 1)
recentFileAct->setShortcut(Qt::ControlModifier + Qt::ShiftModifier + Qt::Key_1);
if(i+1 == 2)
recentFileAct->setShortcut(Qt::ControlModifier + Qt::ShiftModifier + Qt::Key_2);
if(i+1 == 3)
recentFileAct->setShortcut(Qt::ControlModifier + Qt::ShiftModifier + Qt::Key_3);
if(i+1 == 4)
recentFileAct->setShortcut(Qt::ControlModifier + Qt::ShiftModifier + Qt::Key_4);
if(i+1 == 5)
recentFileAct->setShortcut(Qt::ControlModifier + Qt::ShiftModifier + Qt::Key_5);
if(i+1 == 6)
recentFileAct->setShortcut(Qt::ControlModifier + Qt::ShiftModifier + Qt::Key_6);
if(i+1 == 7)
recentFileAct->setShortcut(Qt::ControlModifier + Qt::ShiftModifier + Qt::Key_7);
if(i+1 == 8)
recentFileAct->setShortcut(Qt::ControlModifier + Qt::ShiftModifier + Qt::Key_8);
if(i+1 == 9)
recentFileAct->setShortcut(Qt::ControlModifier + Qt::ShiftModifier + Qt::Key_9);
recentFileAct->setData(files[i]);
recentFileAct->setVisible(true);
}
addSeparator();
addAction(tr("Clear Menu"), this, SLOT(clearMenu()));
setEnabled(numRecentFiles > 0);
}
//
// dtkRecentFilesMenu.cpp ends here
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#pragma once
#include <QMenu>
#include "dtkGuiExport.h"
class DTKGUI_EXPORT dtkRecentFilesMenu : public QMenu
{
Q_OBJECT
Q_PROPERTY(int maxCount READ maxCount WRITE setMaxCount)
public:
dtkRecentFilesMenu(QWidget *parent = 0);
dtkRecentFilesMenu(const QString &title, QWidget *parent = 0);
int maxCount(void) const;
public slots:
void addRecentFile(const QString &fileName);
void clearMenu(void);
void setMaxCount(int);
signals:
void recentFileTriggered(const QString &filename);
private slots:
void menuTriggered(QAction *action);
void updateRecentFileActions(void);
private:
int m_maxCount;
};
//
// dtkRecentFilesMenu.h ends here
#include "dtkScreenMenu.h"
\ No newline at end of file
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#include <dtkConfig.h>
#include "dtkScreenMenu.h"
#if defined(DTK_BUILD_VIDEO) && defined(DTK_HAVE_FFMPEG)
#include <dtkVideo/dtkVideoEncoder.h>
#endif
#include <QtGui>
#include <QtCore>
class dtkScreenMenuPrivate
{
public:
int fps;
int bitrate;
int width;
int height;
public:
QTimer timer;
#if defined(DTK_BUILD_VIDEO) && defined(DTK_HAVE_FFMPEG)
public:
dtkVideoEncoder * encoder;
#endif
};
dtkScreenMenu::dtkScreenMenu(const QString &title, QWidget *parent) : QMenu(title, parent), d(new dtkScreenMenuPrivate)
{
#if defined(DTK_BUILD_VIDEO) && defined(DTK_HAVE_FFMPEG)
d->encoder = NULL;
#endif
d->fps = 10;
d->bitrate = 4000000;
QAction* screenshot = this->addAction(QString("Take screenshot")); screenshot->setVisible(true);
screenshot->setShortcut(Qt::Key_Print);
this->addSeparator();
QAction* screencast_start = this->addAction(QString("Start screencast"));
QAction* screencast_stop = this->addAction(QString("Stop screencast"));
screencast_start->setShortcut(Qt::ControlModifier + Qt::Key_Print);
screencast_stop->setShortcut(Qt::ControlModifier + Qt::ShiftModifier + Qt::Key_Print);
#if !defined(DTK_BUILD_VIDEO) || !defined(DTK_HAVE_FFMPEG)
screencast_start->setEnabled(false);
screencast_stop->setEnabled(false);
#else
connect(screencast_start, SIGNAL(triggered(bool)), this, SLOT(startScreencast(void)));
connect(screencast_stop, SIGNAL(triggered(bool)), this, SLOT(stopScreencast(void)));
#endif
connect(screenshot, SIGNAL(triggered(bool)), this, SLOT(takeScreenshot(void)));
}
void dtkScreenMenu::startScreencast(void)
{
#if defined(DTK_BUILD_VIDEO) && defined(DTK_HAVE_FFMPEG)
if(!d->encoder)
d->encoder = new dtkVideoEncoder;
QString path = QDir::homePath();
QString name = QString("%1 - Screencast - %2").arg(qApp->applicationName()).arg(QDateTime::currentDateTime().toString("MMMM dd yyyy - hh:mm:ss"));
QString file = QDir::home().filePath(name);
QString fileName = QFileDialog::getSaveFileName(this, tr("Save screencast"), file, tr("Screencast (*.avi *.mpg *.mp4 *.mov *.ogv)"));
if(fileName.isEmpty())
return;
if (QWidget * widget = dynamic_cast<QWidget *>(parent())) {
int gop = 20;
int FULLHD = 1920;
d->width = widget->width();
d->height = widget->height();
if (widget->width() > FULLHD) {
d->width = FULLHD;
d->height = widget->height() * FULLHD / widget->width() ;
}
d->encoder->createFile(fileName, d->width, d->height, d->bitrate, gop, d->fps);
}
d->timer.connect(&(d->timer), SIGNAL(timeout()), this, SLOT(addFrameToVideo()));
int interval = 1000/d->fps;
d->timer.start(interval);
#endif
}
void dtkScreenMenu::stopScreencast(void)
{
#if defined(DTK_BUILD_VIDEO) && defined(DTK_HAVE_FFMPEG)
d->encoder->close();
d->timer.stop();
#endif
}
void dtkScreenMenu::addFrameToVideo(void)
{
#if defined(DTK_BUILD_VIDEO) && defined(DTK_HAVE_FFMPEG)
if (QWidget * widget = dynamic_cast<QWidget *>(parent())) {
QImage image = screenshot(widget, d->width);
QPoint mouse_pos= QCursor::pos() - widget->pos();
QPainter painter(&image);
int x = mouse_pos.x();
int y = mouse_pos.y();
int length = 8;
QLine line1(x-length,y,x+length,y);
QLine line2(x,y-length,x,y+length);
painter.setPen( Qt::red );
painter.drawLine(line1);
painter.drawLine(line2);
d->encoder->encodeImage(image);
}
#endif
}
QImage dtkScreenMenu::screenshot(QWidget *widget, qlonglong maxsize)
{
QPixmap pixmap(widget->size());
widget->render(&pixmap);
if( maxsize > 0 && pixmap.width() > maxsize) {
return pixmap.scaledToWidth(maxsize).toImage();
}
return pixmap.toImage();
}
void dtkScreenMenu::takeScreenshot(void)
{
if (QWidget * widget = dynamic_cast<QWidget *>(parent())) {
QString path = QDir::homePath();
QString name = QString("%1 - Screenshot - %2").arg(qApp->applicationName()).arg(QDateTime::currentDateTime().toString("MMMM dd yyyy - hh:mm:ss"));
QString file = QDir::home().filePath(name);
QString fileName = QFileDialog::getSaveFileName(this, tr("Save screenshot"), file, tr("Screenshot (*.png)"));
if(fileName.isEmpty())
return;
QImage image = screenshot(widget);
image.save(fileName, "PNG");
}
}
//
// dtkScreenMenu.cpp ends here
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#pragma once
#include <QtGui>
#include <QtWidgets>
#include "dtkGuiExport.h"
class dtkScreenMenuPrivate;
class DTKGUI_EXPORT dtkScreenMenu : public QMenu
{
Q_OBJECT
public:
dtkScreenMenu(const QString &title, QWidget *parent = 0);
public:
QImage screenshot(QWidget *widget, qlonglong maxsize = 0);
public slots:
void takeScreenshot(void);
void startScreencast(void);
void stopScreencast(void);
protected slots:
void addFrameToVideo(void);
private:
dtkScreenMenuPrivate *d;
};
//
// dtkScreenMenu.h ends here
#include "dtkSpacer.h"
\ No newline at end of file
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#include "dtkSpacer.h"
dtkSpacer::dtkSpacer(QWidget *parent, int width, int height) : QWidget(parent)
{
this->setAttribute(Qt::WA_TransparentForMouseEvents, true);
this->setMinimumSize(width, height);
if(width && !height)
this->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
else if(!width && height)
this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
else
this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
}
dtkSpacer::~dtkSpacer(void)
{
}
QSize dtkSpacer::sizeHint(void) const
{
QSize size = QWidget::sizeHint();
if (size.width() < 1) size.setWidth(1);
if (size.height() < 1) size.setHeight(1);
return(size);
}
//
// dtkSpacer.cpp ends here
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#include <QtWidgets>
#include "dtkGuiExport.h"
class DTKGUI_EXPORT dtkSpacer : public QWidget
{
Q_OBJECT
public:
dtkSpacer(QWidget *parent = 0, int width = 0, int height = 0);
~dtkSpacer(void);
QSize sizeHint (void) const;
};
//
// dtkSpacer.h ends here
#include "dtkSplitter.h"
\ No newline at end of file
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#include <QtGui>
#include "dtkSplitter.h"
// /////////////////////////////////////////////////////////////////
// dtkSplitterHandle
// /////////////////////////////////////////////////////////////////
class dtkSplitterHandle : public QSplitterHandle
{
public:
dtkSplitterHandle(Qt::Orientation orientation, bool slim, QSplitter *parent);
public:
QSize sizeHint(void) const;
protected:
void paintEvent(QPaintEvent * event);
private:
bool m_slim;
};
dtkSplitterHandle::dtkSplitterHandle(Qt::Orientation orientation, bool slim, QSplitter *parent) : QSplitterHandle(orientation, parent)
{
this->m_slim = slim;
}
void dtkSplitterHandle::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event);
QPainter painter(this);
QColor topColor(145, 145, 145);
QColor bottomColor(142, 142, 142);
QColor gradientStart(252, 252, 252);
QColor gradientStop(223, 223, 223);
if (orientation() == Qt::Vertical) {
painter.setPen(topColor);
painter.drawLine(0, 0, width(), 0);
if(m_slim)
return;
painter.setPen(bottomColor);
painter.drawLine(0, height()-1, width(), height()-1);
QLinearGradient linearGrad(QPointF(0, 0), QPointF(0, height()-3));
linearGrad.setColorAt(0, gradientStart);
linearGrad.setColorAt(1, gradientStop);
painter.fillRect(QRect(QPoint(0,1), size() - QSize(0, 2)), QBrush(linearGrad));
} else {
painter.setPen(topColor);
painter.drawLine(0, 0, 0, height());
}
}
QSize dtkSplitterHandle::sizeHint(void) const
{
QSize parent = QSplitterHandle::sizeHint();
if (orientation() == Qt::Vertical) {
return m_slim ? QSize(parent.width(), 1) : parent + QSize(0, 3);
} else {
return QSize(1, parent.height());
}
}
// /////////////////////////////////////////////////////////////////
// dtkSplitterPrivate
// /////////////////////////////////////////////////////////////////
class dtkSplitterPrivate
{
public:
bool slim;
};
// /////////////////////////////////////////////////////////////////
// dtkSplitter
// /////////////////////////////////////////////////////////////////
dtkSplitter::dtkSplitter(QWidget *parent, bool slim) : QSplitter(parent), d(new dtkSplitterPrivate)
{
d->slim = slim;
}
dtkSplitter::~dtkSplitter(void)
{
delete d;
d = NULL;
}
QSplitterHandle *dtkSplitter::createHandle(void)
{
return new dtkSplitterHandle(orientation(), d->slim, this);
}
//
// dtkSplitter.cpp ends here