Browse Source

Implement map export to image

nordsoft 2 năm trước cách đây
mục cha
commit
dee235ea19
3 tập tin đã thay đổi với 23 bổ sung4 xóa
  1. 11 0
      mapeditor/mainwindow.cpp
  2. 3 1
      mapeditor/mainwindow.h
  3. 9 3
      mapeditor/mainwindow.ui

+ 11 - 0
mapeditor/mainwindow.cpp

@@ -1234,3 +1234,14 @@ void MainWindow::on_actionPaste_triggered()
 	}
 }
 
+
+void MainWindow::on_actionExport_triggered()
+{
+	QString fileName = QFileDialog::getSaveFileName(this, "Save to image", QCoreApplication::applicationDirPath(), "BMP (*.bmp);;JPEG (*.jpeg);;PNG (*.png)");
+	if(!fileName.isNull())
+	{
+		auto pixmap = ui->mapView->grab();
+		pixmap.save(fileName);
+	}
+}
+

+ 3 - 1
mapeditor/mainwindow.h

@@ -41,7 +41,7 @@ public:
 	void saveMap();
 	bool openMap(const QString &);
 	
-	MapView * mapView();
+	//MapView * mapView();
 
 	void loadObjectsTree();
 
@@ -115,6 +115,8 @@ private slots:
 
 	void on_actionPaste_triggered();
 
+	void on_actionExport_triggered();
+
 public slots:
 
 	void treeViewSelected(const QModelIndex &selected, const QModelIndex &deselected);

+ 9 - 3
mapeditor/mainwindow.ui

@@ -62,6 +62,7 @@
     <addaction name="actionOpen"/>
     <addaction name="actionSave"/>
     <addaction name="actionSave_as"/>
+    <addaction name="actionExport"/>
    </widget>
    <widget class="QMenu" name="menuMap">
     <property name="title">
@@ -750,7 +751,7 @@
           <x>0</x>
           <y>0</y>
           <width>128</width>
-          <height>257</height>
+          <height>251</height>
          </rect>
         </property>
         <property name="sizePolicy">
@@ -793,7 +794,7 @@
           <x>0</x>
           <y>0</y>
           <width>128</width>
-          <height>257</height>
+          <height>251</height>
          </rect>
         </property>
         <property name="sizePolicy">
@@ -829,7 +830,7 @@
           <x>0</x>
           <y>0</y>
           <width>128</width>
-          <height>257</height>
+          <height>251</height>
          </rect>
         </property>
         <property name="sizePolicy">
@@ -1228,6 +1229,11 @@
     <string notr="true">Ctrl+8</string>
    </property>
   </action>
+  <action name="actionExport">
+   <property name="text">
+    <string>Export as</string>
+   </property>
+  </action>
  </widget>
  <customwidgets>
   <customwidget>