[Kst] branches/work/kst/portto4/kst/src/libkstapp
George Staikos
staikos at kde.org
Wed May 30 20:03:44 CEST 2007
SVN commit 669887 by staikos:
start to implement printing support
M +1 -3 TODO
M +20 -1 document.cpp
M +7 -1 document.h
M +88 -4 mainwindow.cpp
M +6 -0 mainwindow.h
M +9 -0 tabwidget.cpp
M +1 -0 tabwidget.h
--- branches/work/kst/portto4/kst/src/libkstapp/TODO #669886:669887
@@ -45,14 +45,12 @@
Document
--------
- Save
+- Open
- Move data collections into here somehow?
MainWindow
----------
-- Statusbar items
-- Printing
-- Open/Save
- Toolbar
- Mouse modes
--- branches/work/kst/portto4/kst/src/libkstapp/document.cpp #669886:669887
@@ -30,9 +30,28 @@
}
-void Document::save(const QString& to) {
+bool Document::save(const QString& to) {
}
+
+bool Document::open(const QString& file) {
}
+
+QString Document::lastError() const {
+ return QString::null;
+}
+
+
+bool Document::isChanged() const {
+ return true; // FIXME!
+}
+
+
+bool Document::isOpen() const {
+ return true; // FIXME!
+}
+
+}
+
// vim: ts=2 sw=2 et
--- branches/work/kst/portto4/kst/src/libkstapp/document.h #669886:669887
@@ -25,8 +25,14 @@
SessionModel* session() const;
- void save(const QString& to = QString::null);
+ bool open(const QString& file);
+ bool save(const QString& to = QString::null);
+ bool isChanged() const;
+ bool isOpen() const;
+
+ QString lastError() const;
+
private:
SessionModel *_session;
};
--- branches/work/kst/portto4/kst/src/libkstapp/mainwindow.cpp #669886:669887
@@ -91,7 +91,21 @@
}
+bool MainWindow::promptSave() {
+ int rc = QMessageBox::warning(this, tr("Kst"), tr("Your document has been modified.\nSave changes?"), QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Save);
+ if (rc == QMessageBox::Save) {
+ save();
+ } else if (rc == QMessageBox::Cancel) {
+ return false;
+ }
+ return true;
+}
+
+
void MainWindow::closeEvent(QCloseEvent *e) {
+ if (_doc->isChanged() && !promptSave()) {
+ return;
+ }
cleanup();
QMainWindow::closeEvent(e);
}
@@ -112,6 +126,76 @@
}
+void MainWindow::save() {
+ if (_doc->isOpen()) {
+ _doc->save();
+ }
+}
+
+
+void MainWindow::saveAs() {
+ if (_doc->isOpen()) {
+ _doc->save();
+ }
+}
+
+
+void MainWindow::open() {
+ if (_doc->isChanged() && !promptSave()) {
+ return;
+ }
+ QString fn = QFileDialog::getOpenFileName(this, tr("Kst: Open File"), QString(), tr("Kst Sessions (*.kst)"));
+ if (!fn.isEmpty()) {
+ delete _doc;
+ }
+ _doc = new Document;
+ bool ok = _doc->open(fn);
+ if (!ok) {
+ QMessageBox::critical(this, tr("Kst"), tr("Error opening document '%1':\n%2").arg(fn, _doc->lastError()));
+ delete _doc;
+ _doc = new Document;
+ }
+}
+
+
+void MainWindow::print() {
+ if (!_doc->isOpen()) {
+ return;
+ }
+
+ QPrinter printer(QPrinter::HighResolution);
+
+ QPrintDialog pd(&printer, this);
+ pd.addEnabledOption(QPrintDialog::PrintToFile);
+ pd.addEnabledOption(QPrintDialog::PrintPageRange);
+
+ if (pd.exec() == QDialog::Accepted) {
+ QPainter painter(&printer);
+ QList<QGraphicsView*> pages;
+ switch (printer.printRange()) {
+ case QPrinter::PageRange:
+ break;
+ case QPrinter::AllPages:
+ foreach (QGraphicsView *view, _tabWidget->views()) {
+ pages.append(view);
+ }
+ break;
+ case QPrinter::Selection:
+ default:
+ pages.append(_tabWidget->currentView());
+ break;
+ }
+
+ for (int i = 0; i < printer.numCopies(); ++i) {
+ foreach (QGraphicsView *view, pages) {
+ view->render(&painter, QRectF(), QRect(), Qt::KeepAspectRatio /* IgnoreAspectRatio */);
+ printer.newPage();
+ }
+ }
+ }
+}
+
+
void MainWindow::currentViewChanged() {
_undoGroup->setActiveStack(_tabWidget->currentView()->undoStack());
}
@@ -226,19 +310,19 @@
_saveAct = new QAction(tr("&Save"), this);
_saveAct->setStatusTip(tr("Save the current session"));
- //connect(_saveAct, SIGNAL(triggered()), document(), SLOT(save()));
+ connect(_saveAct, SIGNAL(triggered()), this, SLOT(save()));
_saveAsAct = new QAction(tr("Save &as..."), this);
_saveAsAct->setStatusTip(tr("Save the current session"));
- //connect(_saveAsAct, SIGNAL(triggered()), document(), SLOT(saveAs()));
+ connect(_saveAsAct, SIGNAL(triggered()), this, SLOT(saveAs()));
_openAct = new QAction(tr("&Open..."), this);
_openAct->setStatusTip(tr("Open a new session"));
- //connect(_openAct, SIGNAL(triggered()), this, SLOT(openDocument()));
+ connect(_openAct, SIGNAL(triggered()), this, SLOT(open()));
_printAct = new QAction(tr("&Print..."), this);
_printAct->setStatusTip(tr("Print the current view"));
- //connect(_printAct, SIGNAL(triggered()), this, SLOT(print()));
+ connect(_printAct, SIGNAL(triggered()), this, SLOT(print()));
_exitAct = new QAction(tr("E&xit"), this);
_exitAct->setShortcut(tr("Ctrl+Q"));
--- branches/work/kst/portto4/kst/src/libkstapp/mainwindow.h #669886:669887
@@ -44,6 +44,11 @@
void showDataManager();
void showVectorEditor();
+ void save();
+ void saveAs();
+ void open();
+ void print();
+
private Q_SLOTS:
void aboutToQuit();
void about();
@@ -71,6 +76,7 @@
void readSettings();
void writeSettings();
+ bool promptSave();
private:
Document *_doc;
--- branches/work/kst/portto4/kst/src/libkstapp/tabwidget.cpp #669886:669887
@@ -56,6 +56,15 @@
}
+QList<View*> TabWidget::views() const {
+ QList<View*> v;
+ for (int i = 0; i < count(); ++i) {
+ v.append(qobject_cast<View*>(widget(i)));
+ }
+ return v;
+}
+
+
void TabWidget::viewDestroyed(QObject *object) {
View *view = qobject_cast<View*>(object);
removeTab(indexOf(view));
--- branches/work/kst/portto4/kst/src/libkstapp/tabwidget.h #669886:669887
@@ -26,6 +26,7 @@
~TabWidget();
View *currentView() const;
+ QList<View*> views() const;
public Q_SLOTS:
View *createView();
More information about the Kst
mailing list