changeset 13443:1146953baa37

Added image viewer.
author Jacob Dawid <jacob.dawid@googlemail.com>
date Thu, 14 Apr 2011 18:21:27 +0200
parents 6deb6df16986
children 1591f7fde9cd
files gui//Quint.pro gui//src/ImageViewerMdiSubWindow.cpp gui//src/ImageViewerMdiSubWindow.h gui//src/MainWindow.cpp
diffstat 4 files changed, 56 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/gui//Quint.pro
+++ b/gui//Quint.pro
@@ -47,7 +47,8 @@
     src/SyntaxHighlighter.cpp \
     src/BrowserWidget.cpp \
     src/NumberedCodeEdit.cpp \
-    src/SimpleEditor.cpp
+    src/SimpleEditor.cpp \
+    src/ImageViewerMdiSubWindow.cpp
 
 HEADERS += \
         src/TerminalCharacterDecoder.h \
@@ -91,7 +92,8 @@
     src/SyntaxHighlighter.h \
     src/BrowserWidget.h \
     src/NumberedCodeEdit.h \
-    src/SimpleEditor.h
+    src/SimpleEditor.h \
+    src/ImageViewerMdiSubWindow.h
 
 INCFLAGS = -g3 $$system(mkoctfile -p INCFLAGS)
 LFLAGS = $$system(mkoctfile -p LFLAGS) \
new file mode 100644
--- /dev/null
+++ b/gui//src/ImageViewerMdiSubWindow.cpp
@@ -0,0 +1,24 @@
+#include "ImageViewerMdiSubWindow.h"
+#include <QLabel>
+#include <QPixmap>
+#include <QScrollArea>
+
+ImageViewerMdiSubWindow::ImageViewerMdiSubWindow(QPixmap pixmap, QWidget *parent)
+    : QMdiSubWindow(parent),
+      m_pixmap(pixmap) {
+    setWindowTitle("Picture");
+    construct();
+}
+
+void ImageViewerMdiSubWindow::construct() {
+    QLabel *label = new QLabel();
+    label->setBackgroundRole(QPalette::Base);
+    label->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
+    label->setScaledContents(true);
+    label->setPixmap(m_pixmap);
+
+    QScrollArea *scrollArea = new QScrollArea(this);
+    scrollArea->setBackgroundRole(QPalette::Dark);
+    scrollArea->setWidget(label);
+    setWidget(scrollArea);
+}
new file mode 100644
--- /dev/null
+++ b/gui//src/ImageViewerMdiSubWindow.h
@@ -0,0 +1,16 @@
+#ifndef IMAGEVIEWERMDISUBWINDOW_H
+#define IMAGEVIEWERMDISUBWINDOW_H
+
+#include <QMdiSubWindow>
+
+class ImageViewerMdiSubWindow : public QMdiSubWindow
+{
+public:
+    ImageViewerMdiSubWindow(QPixmap pixmap, QWidget *parent = 0);
+
+private:
+    void construct();
+    QPixmap m_pixmap;
+};
+
+#endif // IMAGEVIEWERMDISUBWINDOW_H
--- a/gui//src/MainWindow.cpp
+++ b/gui//src/MainWindow.cpp
@@ -23,6 +23,7 @@
 #include <QDesktopServices>
 #include "MainWindow.h"
 #include "FileEditorMdiSubWindow.h"
+#include "ImageViewerMdiSubWindow.h"
 
 MainWindow::MainWindow(QWidget *parent)
     : QMainWindow(parent),
@@ -38,10 +39,17 @@
 
 void MainWindow::handleOpenFileRequest(QString fileName) {
     reportStatusMessage("Opening file.");
-    FileEditorMdiSubWindow *subWindow = new FileEditorMdiSubWindow(m_openedFiles);
-    m_openedFiles->addSubWindow(subWindow);
-    subWindow->loadFile(fileName);
-    subWindow->showMaximized();
+    QPixmap pixmap;
+    if(pixmap.load(fileName)) {
+        ImageViewerMdiSubWindow *subWindow = new ImageViewerMdiSubWindow(pixmap, this);
+        m_openedFiles->addSubWindow(subWindow);
+        subWindow->showMaximized();
+    } else {
+        FileEditorMdiSubWindow *subWindow = new FileEditorMdiSubWindow(m_openedFiles);
+        m_openedFiles->addSubWindow(subWindow);
+        subWindow->loadFile(fileName);
+        subWindow->showMaximized();
+    }
     m_centralTabWidget->setCurrentWidget(m_openedFiles);
 }