source: projects/punch-card-project/trunk/punch-card-editor/src/deckviewer/cardeditor.cc @ 67

Last change on this file since 67 was 67, checked in by sven, 11 years ago

Irgendwelche alten Aenderungen vom 11.03.2011 von Sven7, der geschrottet wird

File size: 3.9 KB
Line 
1#include "cardeditor.h"
2
3#include <QFileDialog>
4#include <QMessageBox>
5#include <QImageWriter>
6
7using namespace QPunchCard;
8
9CardEditor::CardEditor(App::MainWindow* win) : /*QGraphicsView(win)*/ QScrollArea(win), main(win) {
10        view = new CardWidget(this);
11        setWidget(view);
12        view->unsetCard();
13
14        // neuer, cooler testcode:
15/*
16        view = new CardWidget(this);
17        view->unsetCard();
18
19        QGraphicsScene* scene = new QGraphicsScene();
20        QGraphicsProxyWidget* card_item = scene->addWidget(view);
21        scene->setBackgroundBrush(Qt::red);
22        scene->setSceneRect(0, 0, 3000, 3000);
23
24
25        //setMinimumSize(800, 400);
26
27     setCacheMode(CacheBackground);
28     setViewportUpdateMode(FullViewportUpdate);
29     setRenderHint(QPainter::Antialiasing);
30     setTransformationAnchor(AnchorUnderMouse);
31     setResizeAnchor(AnchorUnderMouse); //ViewCenter);
32
33
34        this->setScene(scene);
35
36        card_item->setPos(QPointF(1000, 1000));
37        fitInView(card_item, Qt::KeepAspectRatio);
38*/
39}
40
41 void CardEditor::keyPressEvent(QKeyEvent *event)
42 {
43     switch (event->key()) {
44     case Qt::Key_Plus:
45             //scene()->setSceneRect(0, 0, scene()->width()*1.2, scene()->height()*1.2);
46             //scale(1.2, 1.2);
47             break;
48     case Qt::Key_Minus:
49             //scene()->setSceneRect(0, 0, scene()->width()*1./1.2, scene()->height()*1./1.2);
50             //scale(1./1.2, 1./1.2);
51             break;
52     default:
53             QScrollArea::keyPressEvent(event);
54         //QGraphicsView::keyPressEvent(event);
55     }
56 }
57
58
59
60void CardEditor::setCard(DeckIndex i) {
61        if(i.assertDeck(main->deck) && i.isValid()) {
62                view->setCard( i.getCard() );
63        } else {
64                qDebug("DeckIndex has not the same deck as we use or is not valid.");
65                qDebug() << i;
66        }
67        this->current_index = i;
68        view->update();
69        setStatusTip( QString("Click to Edit card %1").arg(current_index));
70}
71
72void CardEditor::contentsChanged(DeckIndex lowerCard, DeckIndex upperCard) {
73        if(current_index >= lowerCard && current_index <= upperCard) {
74                view->update();
75        } else {
76                qDebug("contentsChanged: Index was out of bound:");
77                qDebug() << "lower: " << lowerCard << "upper: " << upperCard;
78        }
79}
80
81void CardEditor::fileOpened(bool /*opened*/) {
82        // in jedem Fall: Karte entfernen und neuzeichnen
83        view->unsetCard();
84        view->update();
85        // wenn opened == true => setCard(0) wird schon kommen
86        // ansonsten ist CardWidget schlau genug, nicht den Nullpointer
87        // anzusprechen.
88}
89
90void CardEditor::enterEvent(QEvent* e) {
91        // aeh... wird vielleicht spaeter gebraucht :)
92        QScrollArea::enterEvent(e);
93}
94
95void CardEditor::exportPictureDialog() {
96        // show dialog to export current view to PNG, SVG, etc.
97        /*
98         * TODO: * export all cards at once? (in directory?...)
99         *
100         */
101        Q_ASSERT(this->main);
102        Q_ASSERT(this->view);
103        QString filename = QFileDialog::getSaveFileName(this->main, tr("Choose output file and format by extension"), QString(),
104                tr("Image Files (*.bmp *.jpg *.jpeg *.png *.ppm *.tiff *.xbm *.xpm);;"));
105
106        if(filename.isNull()) {
107                // canceled
108                return;
109        }
110
111        //QFile file(filename);
112        //if(!file.open(QIODevice::WriteOnly)) {
113        /*if(! QFileInfo(filename).isWritable()) {
114                QMessageBox::critical(main, tr("Could not export picture"),
115                        tr("Could not open file <i>%1</i> for writing. Please select a valid filename").arg(filename));
116                // open file dialog another time:
117                exportPictureDialog();
118        }*/
119
120        // get pixmap of actual widget
121        QPixmap pixmap = QPixmap::grabWidget(view);
122        if(!pixmap.save(filename)) {
123                // get list of supported file formats by string
124                QStringList formats;
125                for(int i = 0; i < QImageWriter::supportedImageFormats().count(); i++) {
126                        formats << QString(QImageWriter::supportedImageFormats().at(i));
127                }
128
129                QMessageBox::critical(main, tr("Could not export picture"),
130                        tr("Exporting picture failed. Valid file formats (filename extensions) are %1").
131                        arg( formats.join(", ") ));
132                // open file dialog for another time
133                exportPictureDialog();
134        } else {
135                // finished successfully, tell in status bar
136                main->statusBar()->showMessage(tr("Successfully exported file %1").arg(filename), 4000);
137        }
138}
Note: See TracBrowser for help on using the repository browser.
© 2008 - 2013 technikum29 • Sven Köppel • Some rights reserved
Powered by Trac
Expect where otherwise noted, content on this site is licensed under a Creative Commons 3.0 License