Add option to copy to clipboard as BMP

This commit is contained in:
Robin Stuart 2017-05-15 21:12:19 +01:00
parent a1327cbd0d
commit fd8a4f4d35
3 changed files with 42 additions and 11 deletions

View File

@ -561,7 +561,7 @@ p, li { white-space: pre-wrap; }
</item> </item>
<item> <item>
<layout class="QGridLayout" name="gridLayout_2"> <layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0"> <item row="1" column="0">
<widget class="QPushButton" name="btnAbout"> <widget class="QPushButton" name="btnAbout">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
@ -577,7 +577,7 @@ p, li { white-space: pre-wrap; }
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="4"> <item row="1" column="5">
<widget class="QPushButton" name="btnSave"> <widget class="QPushButton" name="btnSave">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
@ -593,7 +593,7 @@ p, li { white-space: pre-wrap; }
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="5"> <item row="1" column="6">
<widget class="QPushButton" name="btnExit"> <widget class="QPushButton" name="btnExit">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
@ -606,7 +606,7 @@ p, li { white-space: pre-wrap; }
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="1" column="1">
<spacer name="horizontalSpacer_2"> <spacer name="horizontalSpacer_2">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
@ -619,8 +619,8 @@ p, li { white-space: pre-wrap; }
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="0" column="2"> <item row="1" column="3">
<widget class="QPushButton" name="btnCopy"> <widget class="QPushButton" name="btnCopySVG">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>100</width> <width>100</width>
@ -631,7 +631,20 @@ p, li { white-space: pre-wrap; }
<string>Copy to clipboard</string> <string>Copy to clipboard</string>
</property> </property>
<property name="text"> <property name="text">
<string>&amp;Copy</string> <string>Copy S&amp;VG</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="btnCopyBMP">
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>&amp;Copy BMP</string>
</property> </property>
</widget> </widget>
</item> </item>

View File

@ -150,7 +150,8 @@ MainWindow::MainWindow(QWidget* parent, Qt::WindowFlags fl)
connect(btnMoreData, SIGNAL(clicked( bool )), SLOT(open_data_dialog())); connect(btnMoreData, SIGNAL(clicked( bool )), SLOT(open_data_dialog()));
connect(btnSequence, SIGNAL(clicked( bool )), SLOT(open_sequence_dialog())); connect(btnSequence, SIGNAL(clicked( bool )), SLOT(open_sequence_dialog()));
connect(chkHRTHide, SIGNAL(stateChanged( int )), SLOT(update_preview())); connect(chkHRTHide, SIGNAL(stateChanged( int )), SLOT(update_preview()));
connect(btnCopy, SIGNAL(clicked( bool )), SLOT(copy_to_clipboard())); connect(btnCopySVG, SIGNAL(clicked( bool )), SLOT(copy_to_clipboard_svg()));
connect(btnCopyBMP, SIGNAL(clicked( bool )), SLOT(copy_to_clipboard_bmp()));
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
@ -270,14 +271,14 @@ void MainWindow::quit_now()
close(); close();
} }
void MainWindow::copy_to_clipboard() void MainWindow::copy_to_clipboard_svg()
{ {
QClipboard *clipboard = QGuiApplication::clipboard(); QClipboard *clipboard = QGuiApplication::clipboard();
QMimeData *data = new QMimeData; QMimeData *data = new QMimeData;
QString filename = ".zint.svg"; QString filename = ".zint.svg";
double scale = spnScale->value(); double scale = spnScale->value();
spnScale->setValue(10); spnScale->setValue(5);
if (!m_bc.bc.save_to_file(filename)) { if (!m_bc.bc.save_to_file(filename)) {
return; return;
@ -291,6 +292,22 @@ void MainWindow::copy_to_clipboard()
spnScale->setValue(scale); spnScale->setValue(scale);
} }
void MainWindow::copy_to_clipboard_bmp()
{
QClipboard *clipboard = QGuiApplication::clipboard();
QMimeData *data = new QMimeData;
QString filename = ".zint.bmp";
if (!m_bc.bc.save_to_file(filename)) {
return;
}
data->setImageData(QImage(filename));
clipboard->setMimeData(data, QClipboard::Clipboard);
QFile::remove(filename);
}
void MainWindow::change_options() void MainWindow::change_options()
{ {
QUiLoader uiload; QUiLoader uiload;

View File

@ -130,7 +130,8 @@ private slots:
void reset_view(); void reset_view();
int open_data_dialog(); int open_data_dialog();
int open_sequence_dialog(); int open_sequence_dialog();
void copy_to_clipboard(); void copy_to_clipboard_svg();
void copy_to_clipboard_bmp();
private: private:
/* void createActions(); /* void createActions();