~ubuntu-branches/ubuntu/maverick/qgo/maverick

« back to all changes in this revision

Viewing changes to src/textview.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Martin A. Godisch
  • Date: 2005-01-01 23:07:10 UTC
  • Revision ID: james.westby@ubuntu.com-20050101230710-fhng6yidm47xlb2i
Tags: upstream-1.0.0-r2
ImportĀ upstreamĀ versionĀ 1.0.0-r2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
* textview.cpp
 
3
*/
 
4
 
 
5
#include "config.h"
 
6
#include "textview.h"
 
7
#include "matrix.h"
 
8
#include <qmultilineedit.h>
 
9
#include <qtextedit.h>
 
10
#include <qmessagebox.h>
 
11
#include <qfiledialog.h>
 
12
#include <qtextstream.h>
 
13
#include <qclipboard.h> 
 
14
#include <qapplication.h>
 
15
 
 
16
/* 
 
17
*  Constructs a TextView which is a child of 'parent', with the 
 
18
*  name 'name' and widget flags set to 'f' 
 
19
*
 
20
*  The dialog will by default be modeless, unless you set 'modal' to
 
21
*  TRUE to construct a modal dialog.
 
22
*/
 
23
TextView::TextView(QWidget* parent, const char* name, bool modal, WFlags fl)
 
24
: TextViewGUI( parent, name, modal, fl )
 
25
{
 
26
        textEdit->setWordWrap(QTextEdit::FixedColumnWidth);
 
27
        textEdit->setWrapColumnOrWidth(80);
 
28
        QFont f("fixed", 10);
 
29
        f.setStyleHint(QFont::TypeWriter);
 
30
        textEdit->setFont(f);
 
31
}
 
32
 
 
33
/*  
 
34
*  Destroys the object and frees any allocated resources
 
35
*/
 
36
TextView::~TextView()
 
37
{
 
38
        // no need to delete child widgets, Qt does it all for us
 
39
}
 
40
 
 
41
/* 
 
42
* public slot
 
43
*/
 
44
void TextView::saveMe()
 
45
{
 
46
        QString fileName(QFileDialog::getSaveFileName(QString::null,
 
47
                tr("Text Files (*.txt);;All Files (*)"),
 
48
                this));
 
49
        if (fileName.isEmpty())
 
50
                return;
 
51
        
 
52
        QFile file(fileName);
 
53
        
 
54
        // Confirm overwriting file.
 
55
        if (QFile(fileName).exists())
 
56
                if (QMessageBox::information(this, PACKAGE,
 
57
                        tr("This file already exists. Do you want to overwrite it?"),
 
58
                        tr("Yes"), tr("No"), 0, 0, 1) == 1)
 
59
                        return;
 
60
                
 
61
                if (!file.open(IO_WriteOnly))
 
62
                {
 
63
                        QString s;
 
64
                        s.sprintf(tr("Failed to write to file") + " %s", fileName.latin1());
 
65
                        QMessageBox::warning(this, PACKAGE, s);
 
66
                        return;
 
67
                }
 
68
                
 
69
                QTextStream stream(&file);
 
70
                stream << textEdit->text();
 
71
                file.close();
 
72
}
 
73
 
 
74
void TextView::setMatrix(Matrix *m, ASCII_Import *charset)
 
75
{
 
76
        CHECK_PTR(m);
 
77
        textEdit->setText(m->printMe(charset));
 
78
}
 
79
 
 
80
void TextView::toClipboard()
 
81
{
 
82
        QApplication::clipboard()->setText(textEdit->text());
 
83
}