6 QWidget* parent, Qt::WindowFlags flags ) : QMainWindow( parent, flags )
11 if ( extension.contains(
"/" ) )
14 if ( extension.startsWith(
"results" ) )
17 else if ( extension.startsWith(
"reports" ) )
20 else if ( extension.startsWith(
"data" ) )
36 QMenu* fileMenu =
edMenuBar->addMenu( tr(
"&File" ) );
47 loadAction =
new QAction( tr(
"&Load" ),
this );;
48 loadAction->setShortcut( tr(
"Ctrl+L" ) );
49 connect( loadAction, SIGNAL( triggered() ),
this, SLOT(
load() ) );
51 saveAction =
new QAction( tr(
"&Save" ),
this );;
52 saveAction->setShortcut( tr(
"Ctrl+S" ) );
53 connect( saveAction, SIGNAL( triggered() ),
this, SLOT(
save() ) );
55 fileMenu->addAction( loadAction );
56 fileMenu->addAction( saveAction );
60 QAction* saveAsAction =
new QAction( tr(
"Save&As" ),
this );;
61 saveAsAction->setShortcut( tr(
"Ctrl+A" ) );
62 connect( saveAsAction, SIGNAL( triggered() ),
this, SLOT(
saveAs() ) );
64 QAction* clearAction =
new QAction( tr(
"Clear" ),
this );;
65 connect( clearAction, SIGNAL( triggered() ),
this, SLOT(
clear() ) );
67 QAction* printAction =
new QAction( tr(
"&Print" ),
this );;
68 printAction->setShortcut( tr(
"Ctrl+P" ) );
69 connect( printAction, SIGNAL( triggered() ),
this, SLOT(
print() ) );
71 QAction* fontAction =
new QAction( tr(
"&Font" ),
this );;
72 fontAction->setShortcut( tr(
"Ctrl+F" ) );
73 connect( fontAction, SIGNAL( triggered() ),
this, SLOT(
update_font() ) );
75 fileMenu->addAction( saveAsAction );
76 fileMenu->addAction( printAction );
77 fileMenu->addAction( fontAction );
78 fileMenu->addAction( clearAction );
88 e =
new QTextEdit(
this );
91 e->setAcceptRichText(
true );
92 e->setWordWrapMode ( QTextOption::WrapAtWordBoundaryOrAnywhere );
93 e->setReadOnly ( readonly );
94 setCentralWidget (
e );
102 fn = QFileDialog::getOpenFileName(
this,
107 if ( fn ==
"" )
return;
113 if ( f.open( QIODevice::ReadOnly | QIODevice::Text ) )
120 e->setPlainText( text );
125 QMessageBox::information(
this,
127 tr(
"Could not open\n\n" ) + fn + tr(
"\n\n for reading." ) );
142 fn = QFileDialog::getSaveFileName(
this );
144 if ( ! fn.isEmpty( ) )
153 QString text =
e->toPlainText();
157 if ( f.open( QIODevice::WriteOnly | QIODevice::Text ) )
165 QMessageBox::information(
this,
167 tr(
"Could not open\n\n" ) +
filename + tr(
"\n\n for writing." ) );
173 QFont newFont = QFontDialog::getFont( &ok,
currentFont,
this );
185 QPrintDialog* dialog =
new QPrintDialog( &printer,
this );
187 dialog->setWindowTitle( tr(
"Print Document" ) );
189 if ( dialog->exec() != QDialog::Accepted )
return;
191 QStringList text =
e->toPlainText().split(
"\n" );
195 p.setFont(
e->font() );
198 QFontMetrics fm = p.fontMetrics();
200 const int MARGIN = 10;
202 for (
int i = 0; i < text.size(); i++ )
204 if ( MARGIN + yPos > printer.height( ) - MARGIN )
210 p.drawText( MARGIN, MARGIN + yPos,
211 printer.width(), fm.lineSpacing(),
212 Qt::TextExpandTabs, text[ i ] );
214 yPos = yPos + fm.lineSpacing();