Commit d24e0767 authored by WINTZ Julien's avatar WINTZ Julien

Move relevant classes from gui support to widgets.

parent 1534b6da
### CMakeLists.txt ---
## Version: $Id$
##
######################################################################
##
### Commentary:
##
######################################################################
##
### Change Log:
##
######################################################################
##
### Code:
project(dtkGuiSupport)
......@@ -23,12 +34,8 @@ 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
......@@ -54,11 +61,7 @@ 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
......@@ -159,3 +162,6 @@ install(TARGETS ${PROJECT_NAME}
DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT guisupport
EXPORT dtkDepends)
######################################################################
### CMakeLists.txt ends here
/* dtkScreensMenu.cpp ---
*
* Author: Julien Wintz
* Copyright (C) 2008 - Julien Wintz, Inria.
* Created: Tue Jun 8 13:45:35 2010 (+0200)
*/
/* Commentary:
*
*/
/* Change log:
*
*/
#include <dtkConfig.h>
#include "dtkScreenMenu.h"
#if defined(DTK_BUILD_VIDEO) && defined(DTK_HAVE_FFMPEG)
#include <dtkVideo/dtkVideoEncoder.h>
#endif
#include <QtWidgets>
#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");
}
}
/* dtkSpacer.h ---
*
* Author: Julien Wintz
* Copyright (C) 2008 - Julien Wintz, Inria.
* Created: Tue Oct 7 09:21:29 2008 (+0200)
* Version: $Id$
* Last-Updated: Thu May 14 22:27:40 2009 (+0200)
* By: Julien Wintz
* Update #: 15
*/
/* Commentary:
*
*/
/* Change log:
*
*/
#ifndef DTKSPACER_H
#define DTKSPACER_H
#include <QWidget>
#include "dtkGuiSupportExport.h"
class DTKGUISUPPORT_EXPORT dtkSpacer : public QWidget
{
Q_OBJECT
public:
dtkSpacer(QWidget *parent = 0, int width = 0, int height = 0);
~dtkSpacer(void);
QSize sizeHint (void) const;
};
#endif
/* dtkSplitter.h ---
*
* Author: Julien Wintz
* Copyright (C) 2008 - Julien Wintz, Inria.
* Created: Tue Oct 7 23:16:58 2008 (+0200)
* Version: $Id$
* Last-Updated: Wed Mar 21 10:47:52 2012 (+0100)
* By: Julien Wintz
* Update #: 37
*/
/* Commentary:
*
*/
/* Change log:
*
*/
#ifndef DTKSPLITTER_H
#define DTKSPLITTER_H
#include <QSplitter>
#include <dtkCoreSupport/dtkGlobal.h>
#include "dtkGuiSupportExport.h"
class dtkSplitterPrivate;
class DTKGUISUPPORT_EXPORT dtkSplitter : public QSplitter
{
Q_OBJECT
public:
dtkSplitter(QWidget *parent = 0, bool slim = true);
~dtkSplitter(void);
QSplitterHandle *createHandle(void);
private:
dtkSplitterPrivate *d;
};
#endif
### CMakeLists.txt ---
## Version: $Id$
##
######################################################################
##
### Commentary:
##
## Author: Julien Wintz
## Created: Mon Apr 15 11:46:27 2013 (+0200)
## Version:
## Last-Updated: lun. avril 7 11:13:47 2014 (+0200)
## By: Nicolas Niclausse
## Update #: 58
######################################################################
##
### Change Log:
##
######################################################################
##
### Code:
project(dtkWidgets)
......@@ -29,6 +29,10 @@ set(${PROJECT_NAME}_HEADERS
dtkObjectEditor.h
dtkPropertyEditor.h
dtkPropertyEditorFactory.h
dtkRecentFilesMenu.h
dtkScreenMenu.h
dtkSpacer.h
dtkSplitter.h
dtkToolBox.h
dtkWidgets
dtkWidgetsLogView.h
......@@ -44,8 +48,7 @@ set(${PROJECT_NAME}_HEADERS
dtkWidgetsTagCloudScopeItem.h
dtkWidgetsTagCloudView.h
dtkWidgetFactory.h
dtkWidgetFactory.tpp
)
dtkWidgetFactory.tpp)
set(${PROJECT_NAME}_SOURCES
dtkApplication.cpp
......@@ -57,6 +60,10 @@ set(${PROJECT_NAME}_SOURCES
dtkObjectEditor.cpp
dtkPropertyEditor.cpp
dtkPropertyEditorFactory.cpp
dtkRecentFilesMenu.cpp
dtkScreenMenu.cpp
dtkSpacer.cpp
dtkSplitter.cpp
dtkToolBox.cpp
dtkWidgetsLogView.cpp
dtkWidgetsTag.cpp
......@@ -68,8 +75,7 @@ set(${PROJECT_NAME}_SOURCES
dtkWidgetsTagCloudList.cpp
dtkWidgetsTagCloudScope.cpp
dtkWidgetsTagCloudScopeItem.cpp
dtkWidgetsTagCloudView.cpp
)
dtkWidgetsTagCloudView.cpp)
set(${PROJECT_NAME}_SOURCES_RCC
dtkNotification.qrc
......@@ -145,3 +151,6 @@ install(TARGETS ${PROJECT_NAME}
DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT widgets
EXPORT dtkDepends)
######################################################################
### CMakeLists.txt ends here
/* dtkRecentFilesMenu.cpp ---
*
* Author: Julien Wintz
* Copyright (C) 2008 - Julien Wintz, Inria.
* Created: Tue Jun 8 13:45:35 2010 (+0200)
* Version: $Id$
* Last-Updated: Thu Feb 3 13:51:59 2011 (+0100)
* By: Julien Wintz
* Update #: 16
*/
/* Commentary:
*
*/
/* Change log:
*
*/
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#include "dtkRecentFilesMenu.h"
#include <QSettings>
#include <QFileInfo>
#include <QtCore>
dtkRecentFilesMenu::dtkRecentFilesMenu(QWidget *parent) : QMenu(parent), m_maxCount(8)
{
......@@ -116,3 +110,6 @@ void dtkRecentFilesMenu::updateRecentFileActions(void)
setEnabled(numRecentFiles > 0);
}
//
// dtkRecentFilesMenu.cpp ends here
/* dtkRecentFilesMenu.h ---
*
* Author: Julien Wintz
* Copyright (C) 2008 - Julien Wintz, Inria.
* Created: Tue Jun 8 13:38:19 2010 (+0200)
* Version: $Id$
* Last-Updated: Tue Jun 8 14:01:54 2010 (+0200)
* By: Julien Wintz
* Update #: 9
*/
// Version: $Id$
//
//
/* Commentary:
*
*/
// Commentary:
//
//
/* Change log:
*
*/
// Change Log:
//
//
#ifndef DTKRECENTFILESMENU_H
#define DTKRECENTFILESMENU_H
// Code:
#include <QMenu>
#pragma once
#include "dtkGuiSupportExport.h"
#include <QtWidgets>
class DTKGUISUPPORT_EXPORT dtkRecentFilesMenu : public QMenu
#include "dtkWidgetsExport.h"
class DTKWIDGETS_EXPORT dtkRecentFilesMenu : public QMenu
{
Q_OBJECT
Q_PROPERTY(int maxCount READ maxCount WRITE setMaxCount)
......@@ -51,4 +45,5 @@ private:
int m_maxCount;
};
#endif // DTKRECENTFILEMENU_H
//
// dtkRecentFilesMenu.h ends here
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#include "dtkScreenMenu.h"
#include <QtWidgets>
#include <QtCore>
class dtkScreenMenuPrivate
{
public:
int width;
int height;
};
dtkScreenMenu::dtkScreenMenu(const QString &title, QWidget *parent) : QMenu(title, parent), d(new dtkScreenMenuPrivate)
{
QAction* screenshot = this->addAction(QString("Take screenshot")); screenshot->setVisible(true);
screenshot->setShortcut(Qt::Key_Print);
connect(screenshot, SIGNAL(triggered(bool)), this, SLOT(takeScreenshot(void)));
}
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
/* dtkScreenMenu.h ---
*
* Author: Nicolas Niclausse
* Copyright (C) 2013 - Nicolas Niclausse, Inria.
* Created: ven. oct. 18 14:45:04 2013 (+0200)
*/
// Version: $Id$
//
//
/* Commentary:
*
*/
// Commentary:
//
//
// Change Log:
//
//
// Code:
/* Change log:
*
*/
#ifndef DTKSCREENMENU_H
#define DTKSCREENMENU_H
#include <QMenu>
#include <QImage>
#include <QtGui>
#include <QtWidgets>
#include "dtkGuiSupportExport.h"
#include "dtkWidgetsExport.h"
class dtkScreenMenuPrivate;
class DTKGUISUPPORT_EXPORT dtkScreenMenu : public QMenu
class DTKWIDGETS_EXPORT dtkScreenMenu : public QMenu
{
Q_OBJECT
......@@ -35,14 +35,12 @@ public:
public slots:
void takeScreenshot(void);
void startScreencast(void);
void stopScreencast(void);
protected slots:
void addFrameToVideo(void);
private:
dtkScreenMenuPrivate *d;
};
#endif // DTKSCREENMENU_H
//
// dtkScreenMenu.h ends here
/* dtkSpacer.cpp ---
*
* Author: Julien Wintz
* Copyright (C) 2008 - Julien Wintz, Inria.
* Created: Tue Oct 7 09:25:06 2008 (+0200)
* Version: $Id$
* Last-Updated: Fri Mar 23 13:31:15 2012 (+0100)
* By: Julien Wintz
* Update #: 26
*/
/* Commentary:
*
*/
/* Change log:
*
*/
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#include "dtkSpacer.h"
......@@ -37,10 +32,13 @@ dtkSpacer::~dtkSpacer(void)
}
QSize dtkSpacer::sizeHint(void) const
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 <QWidget>
#include "dtkWidgetsExport.h"
class DTKWIDGETS_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
/* dtkSplitter.cpp ---
*
* Author: Julien Wintz
* Copyright (C) 2008 - Julien Wintz, Inria.
* Created: Tue Oct 7 23:24:59 2008 (+0200)
* Version: $Id$
* Last-Updated: Wed Mar 21 10:53:40 2012 (+0100)
* By: Julien Wintz
* Update #: 104
*/
/* Commentary:
*
*/
/* Change log:
*
*/
#include <QtWidgets>
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#include "dtkSplitter.h"
......@@ -33,14 +26,14 @@ public:
public:
QSize sizeHint(void) const;
protected:
protected:
void paintEvent(QPaintEvent * event);
private:
bool m_slim;
};
dtkSplitterHandle::dtkSplitterHandle(Qt::Orientation orientation, bool slim, QSplitter *parent) : QSplitterHandle(orientation, parent)
dtkSplitterHandle::dtkSplitterHandle(Qt::Orientation orientation, bool slim, QSplitter *parent) : QSplitterHandle(orientation, parent)