Graphic record GIF support
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
#include <QScrollArea>
|
||||
#include <QTimer>
|
||||
#include <QInputDialog>
|
||||
#include "gif.h"
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
|
||||
# include <QRandomGenerator>
|
||||
#endif
|
||||
@@ -64,6 +65,7 @@ protected:
|
||||
|
||||
Graphic::Graphic(QWidget * parent): QFrame(parent), canvas(0), line_x_min(this), line_x_max(this), line_y_min(this), line_y_max(this) {
|
||||
canvas_gl = 0;
|
||||
timer_pause = timer_record = 0;
|
||||
gesture_angle = 45.;
|
||||
leg_update = true;
|
||||
visible_update = fullscr = need_mouse_pan = m_fakeGL = false;
|
||||
@@ -92,6 +94,7 @@ Graphic::Graphic(QWidget * parent): QFrame(parent), canvas(0), line_x_min(this),
|
||||
ui->graphic_buttonConfigure,
|
||||
ui->graphic_buttonSave,
|
||||
ui->graphic_buttonExport,
|
||||
ui->graphic_buttonRecord,
|
||||
ui->graphic_buttonClear,
|
||||
ui->graphic_buttonClose};
|
||||
buttons_menu = new QMenu(this);
|
||||
@@ -238,11 +241,18 @@ void Graphic::showEvent(QShowEvent *) {
|
||||
}
|
||||
|
||||
|
||||
void Graphic::timerEvent(QTimerEvent * ) {
|
||||
pause_phase += 0.02;
|
||||
if (pause_phase > 1.)
|
||||
pause_phase -= 1.;
|
||||
update();
|
||||
void Graphic::timerEvent(QTimerEvent * e) {
|
||||
if (e->timerId() == timer_pause) {
|
||||
pause_phase += 0.02;
|
||||
if (pause_phase > 1.)
|
||||
pause_phase -= 1.;
|
||||
update();
|
||||
}
|
||||
if (e->timerId() == timer_record) {
|
||||
QPixmap im(canvas->size());
|
||||
canvas->render(&im);
|
||||
record_imgs << im.toImage();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -788,6 +798,7 @@ void Graphic::setButtons(Graphic::Buttons b) {
|
||||
ui->graphic_buttonExport->setVisible(b.testFlag(Export));
|
||||
ui->graphic_buttonClose->setVisible(b.testFlag(Close));
|
||||
ui->graphic_checkPause->setVisible(b.testFlag(Pause));
|
||||
ui->graphic_buttonRecord->setVisible(b.testFlag(Record));
|
||||
if (ui->graphic_buttonAutofit ->isVisible() || ui->graphic_checkGrid ->isVisible() || ui->graphic_checkGuides->isVisible() ||
|
||||
ui->graphic_buttonConfigure->isVisible() || ui->graphic_buttonSave->isVisible() || ui->graphic_checkPause ->isVisible())
|
||||
ui->verticalSpacer->changeSize(0, 30, QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||||
@@ -1913,6 +1924,39 @@ void Graphic::on_graphic_buttonExport_clicked() {
|
||||
}
|
||||
|
||||
|
||||
void Graphic::on_graphic_buttonRecord_clicked(bool checked) {
|
||||
if (checked) {
|
||||
record_imgs.clear();
|
||||
timer_record = startTimer(100);
|
||||
} else {
|
||||
killTimer(timer_record);
|
||||
timer_record = 0;
|
||||
if (record_imgs.isEmpty()) return;
|
||||
QString f = QFileDialog::getSaveFileName(this, tr("Save GIF"), ppath, "GIF(*.gif)");
|
||||
if (!f.isEmpty()) {
|
||||
GifWriter gif_writer;
|
||||
int frame_delay = 10;
|
||||
if (GifBegin(&gif_writer, f.toUtf8(), static_cast<uint32_t>(record_imgs.first().width()),
|
||||
static_cast<uint32_t>(record_imgs.first().height()),
|
||||
static_cast<uint32_t>(frame_delay))) {
|
||||
for (const QImage & im : record_imgs) {
|
||||
if (!GifWriteFrame(&gif_writer,
|
||||
im.convertToFormat(QImage::Format_Indexed8).convertToFormat(QImage::Format_RGBA8888).constBits(),
|
||||
static_cast<uint32_t>(im.width()),
|
||||
static_cast<uint32_t>(im.height()),
|
||||
static_cast<uint32_t>(frame_delay))) {
|
||||
GifEnd(&gif_writer);
|
||||
qDebug() << "GifWriteFrame ERROR";
|
||||
}
|
||||
}
|
||||
GifEnd(&gif_writer);
|
||||
}
|
||||
}
|
||||
record_imgs.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Graphic::on_graphic_checkGuides_toggled(bool checked) {
|
||||
guides = checked;
|
||||
setGuidesCursor();
|
||||
|
||||
Reference in New Issue
Block a user