diff -r 21379539d952 -r f94317a94db1 texteditor.cpp
--- a/texteditor.cpp Wed Jul 05 10:29:54 2006 +0000
+++ b/texteditor.cpp Thu Jul 06 14:47:01 2006 +0000
@@ -1,24 +1,17 @@
#include "texteditor.h"
-#include
-#include
-#include
-#include
-#include
-#include
-#include
+#include
+#include
+#include
+#include
#include
-#include
#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-//Added by qt3to4:
-#include
+#include
+#include
+#include
+#include
+#include
+#include
#include
#include
@@ -29,7 +22,6 @@
#include "noteobj.h"
#include "version.h"
-extern Q3Canvas* actCanvas;
extern int statusbarTime;
extern QSettings settings;
@@ -56,6 +48,7 @@
e->setTextFormat(Qt::RichText); // default
e->setTabStopWidth (20); // unit is pixel
e->setColor (Qt::black);
+ e->setAutoFillBackground (true);
connect (e, SIGNAL( textChanged() ), this, SLOT( editorChanged() ) );
setCentralWidget( e );
statusBar()->message( "Ready", statusbarTime);
@@ -68,9 +61,6 @@
setupSettingsActions();
// Various states
- emptyPaper = QBrush(Qt::gray);
- filledPaper = QBrush(Qt::white);
- inactivePaper= QBrush(Qt::black);
setInactive();
// Load Settings
@@ -137,7 +127,7 @@
bool TextEditor::isEmpty()
{
- if (e->text().length())
+ if (e->toPlainText().length()>0)
return false;
else
return true;
@@ -208,10 +198,9 @@
return filenameHint;
}
-bool TextEditor::findText(const QString &t, const bool &cs)
+bool TextEditor::findText(const QString &t, const QTextDocument::FindFlags &flags)
{
- bool wo=false; // word matches
- if (e->find (t, cs, wo, true, 0, 0 ))
+ if (e->find (t,flags))
return true;
else
return false;
@@ -358,18 +347,20 @@
// comboFont = new QComboBox( true, tb );
comboFont = new QComboBox;
tb->addWidget (comboFont);
- QFontDatabase db;
- comboFont->insertStringList( db.families() );
+ QFontDatabase fontDB;
+ comboFont->insertStringList( fontDB.families() );
connect( comboFont, SIGNAL( activated( const QString & ) ),
this, SLOT( textFamily( const QString & ) ) );
comboFont->addItem( QApplication::font().family() );
-// comboSize = new QComboBox( true, tb );
comboSize = new QComboBox;
tb->addWidget (comboSize);
- Q3ValueList sizes = db.standardSizes();
- Q3ValueList::Iterator it = sizes.begin();
- for ( ; it != sizes.end(); ++it )
- comboSize->insertItem( QString::number( *it ) );
+ QList sizes=fontDB.standardSizes();
+ QList::iterator i = sizes.begin();
+ while (i != sizes.end())
+ {
+ ++i; // increment i before using it
+ comboSize->insertItem ( QString::number(*i));
+ }
connect( comboSize, SIGNAL( activated( const QString & ) ),
this, SLOT( textSize( const QString & ) ) );
comboSize->addItem ( QString::number( QApplication::font().pointSize() ) );
@@ -461,10 +452,12 @@
this, SLOT( fontChanged( const QFont & ) ) );
connect( e, SIGNAL( currentColorChanged( const QColor & ) ),
this, SLOT( colorChanged( const QColor & ) ) );
+ /*
connect( e, SIGNAL( currentAlignmentChanged( int ) ),
this, SLOT( alignmentChanged( int ) ) );
connect( e, SIGNAL( currentVerticalAlignmentChanged(int)),
this, SLOT( verticalAlignmentChanged(int)));
+ */
}
@@ -497,7 +490,7 @@
{
if (state!=inactiveEditor)
{
- if (e->length())
+ if (e->text().length())
{
QMessageBox mb( __VYM " - " +tr("Note Editor"),
"Loading will overwrite the existing note",
@@ -513,9 +506,13 @@
}
}
// Load note
- Q3FileDialog *fd=new Q3FileDialog( this);
- fd->addFilter ("ASCII texts (*.txt)");
- fd->addFilter ("VYM notes (*.html)");
+ QFileDialog *fd=new QFileDialog( this);
+ QStringList types;
+ types<< "VYM notes (*.html)" <<
+ "ASCII texts (*.txt)" <<
+ "All filed (*)";
+ fd->setFilters (types);
+ fd->setDirectory (QDir().current());
fd->show();
QString fn;
if ( fd->exec() == QDialog::Accepted )
@@ -544,7 +541,10 @@
QString TextEditor::getText()
{
- return e->text();
+ if (e->toPlainText().isEmpty())
+ return "";
+ else
+ return e->text();
}
void TextEditor::editorChanged()
@@ -555,9 +555,9 @@
state=filledEditor;
if (state==emptyEditor)
- e->setPaper (emptyPaper);
+ setState (emptyEditor);
else
- e->setPaper (filledPaper);
+ setState (filledEditor);
// SLOT is LinkableMapObj, which will update systemFlag
emit (textHasChanged() );
}
@@ -565,12 +565,8 @@
void TextEditor::setText(QString t)
{
- if ( !Q3StyleSheet::mightBeRichText( t ) )
- t = Q3StyleSheet::convertFromPlainText( t, Q3StyleSheetItem::WhiteSpaceNormal );
e->setReadOnly(false);
e->setText(t);
-// editorChanged(); //not called automagically FIXME or is it?
-
enableActions();
}
@@ -578,7 +574,7 @@
{
state=inactiveEditor;
setText("");
- e->setPaper (inactivePaper);
+ setState (inactiveEditor);
e->setReadOnly (true);
disableActions();
@@ -592,7 +588,7 @@
void TextEditor::textSaveAs()
{
- QString fn = Q3FileDialog::getSaveFileName( QString::null, "VYM Note (HTML) (*.html);;All files (*)",
+ QString fn = QFileDialog::getSaveFileName( QString::null, "VYM Note (HTML) (*.html);;All files (*)",
this,"export note dialog",tr("Export Note to single file") );
if ( !fn.isEmpty() )
@@ -662,9 +658,21 @@
// In X11 a copy&paste generates paragraphs,
// which is not always wanted
// This function replaces paragraphs by linebreaks.
+
+ e->setBackgroundRole (QPalette::Text);
+ cout << "dark\n";
+
+ QString t;
+ t=e->text();
+ QRegExp re("");
+ re.setMinimal(true);
+ t.replace (re,"");
+ t.replace ("
","
");
+ e->setText(t);
+
+ /* FIXME QT3 use seletion ()
int parFrom, parTo, indFrom, indTo;
e->getSelection (&parFrom,&indFrom,&parTo,&indTo);
- QString t;
if (parFrom>-1)
t=e->selectedText();
else
@@ -687,10 +695,15 @@
e->setText (e->text().replace(marker,t));
} else
e->setText(t);
+ */
}
void TextEditor::textJoinLines()
{
+ e->setBackgroundRole (QPalette::Light);
+ cout << "light\n";
+
+/* FIXME QT3
int parFrom, parTo, indFrom, indTo;
e->getSelection (&parFrom,&indFrom,&parTo,&indTo);
QString t;
@@ -721,6 +734,7 @@
e->setText (e->text().replace(marker,t));
} else
e->setText(t);
+*/
}
void TextEditor::textExportAsASCII()
@@ -735,7 +749,7 @@
s=filenameHint;
} else
s=QString::null;
- fn = Q3FileDialog::getSaveFileName( s, "VYM Note (ASCII) (*.txt);;All files (*)", this,"export note dialog",tr("Export Note to single file (ASCII)") );
+ fn = QFileDialog::getSaveFileName( s, "VYM Note (ASCII) (*.txt);;All files (*)", this,"export note dialog",tr("Export Note to single file (ASCII)") );
int ret=-1;
if ( !fn.isEmpty() )
@@ -776,41 +790,16 @@
void TextEditor::textPrint()
{
- printer->setFullPage(TRUE);
- if ( printer->setup( this ) )
- {
- QPainter p( printer );
- // Check that there is a valid device to print to.
- if ( !p.device() ) return;
- Q3PaintDeviceMetrics metrics( p.device() );
- int dpiy = metrics.logicalDpiY();
- int margin = (int) ( (2/2.54)*dpiy ); // 2 cm margins
- QRect body( margin, margin, metrics.width() - 2*margin, metrics.height() - 2*margin );
- QFont font( e->currentFont() );
- font.setPointSize( 10 ); // we define 10pt to be a nice base size for printing
- Q3SimpleRichText richText( e->text(), font,
- e->context(),
- e->styleSheet(),
- e->mimeSourceFactory(),
- body.height() );
- richText.setWidth( &p, body.width() );
- QRect view( body );
- int page = 1;
- do
- {
- richText.draw( &p, body.left(), body.top(), view, colorGroup() );
- view.moveBy( 0, body.height() );
- p.translate( 0 , -body.height() );
- p.setFont( font );
- p.drawText( view.right() - p.fontMetrics().width( QString::number( page ) ),
- view.bottom() + p.fontMetrics().ascent() + 5, QString::number( page ) );
- if ( view.top() >= richText.height() )
- break;
- printer->newPage();
- page++;
- } while (TRUE);
- }
+ QTextDocument *document = e->document();
+ QPrinter printer;
+
+ QPrintDialog *dialog = new QPrintDialog(&printer, this);
+ dialog->setWindowTitle(tr("Print Document"));
+ if (dialog->exec() != QDialog::Accepted)
+ return;
+
+ document->print(&printer);
}
void TextEditor::textEditUndo()
@@ -820,12 +809,12 @@
void TextEditor::toggleFonthint()
{
setUpdatesEnabled (false);
- e->selectAll (true);
+ e->selectAll ();
if (!actionFormatUseFixedFont->isOn() )
e->setCurrentFont (varFont);
else
e->setCurrentFont (fixedFont);
- e->selectAll (false);
+ e->selectAll ();
setUpdatesEnabled (true);
repaint();
}
@@ -901,13 +890,15 @@
void TextEditor::textVAlign()
{
+/* FIXME QT3
if ( sender() == actionAlignSuperScript && actionAlignSuperScript->isOn()) {
- e->setVerticalAlignment( Q3TextEdit::AlignSuperScript);
+ e->setVerticalAlignment( QTextEdit::AlignSuperScript);
} else if (sender() == actionAlignSubScript && actionAlignSubScript->isOn()) {
- e->setVerticalAlignment( Q3TextEdit::AlignSubScript);
+ e->setVerticalAlignment( QTextEdit::AlignSubScript);
} else {
- e->setVerticalAlignment( Q3TextEdit::AlignNormal);
+ e->setVerticalAlignment( QTextEdit::AlignNormal);
}
+*/
}
@@ -943,16 +934,18 @@
void TextEditor::verticalAlignmentChanged(int a)
{
- if (a == Q3TextEdit::AlignSuperScript ) {
+ /* FIXME QT3
+ if (a == QTextEdit::AlignSuperScript ) {
actionAlignSuperScript->setOn(true);
actionAlignSubScript->setOn(false);
- } else if (a == Q3TextEdit::AlignSubScript ) {
+ } else if (a == QTextEdit::AlignSubScript ) {
actionAlignSuperScript->setOn(false);
actionAlignSubScript->setOn(true);
} else {
actionAlignSuperScript->setOn(false);
actionAlignSubScript->setOn(false);
}
+ */
}
@@ -991,4 +984,20 @@
actionFormatUseFixedFont->setEnabled(false);
}
+void TextEditor::setState (EditorState s)
+{
+
+ QPalette p=palette();
+ QColor c;
+ switch (s)
+ {
+ case emptyEditor: c=QColor (150,150,150); break;
+ case filledEditor: c=QColor (255,255,255); break;
+ case inactiveEditor: c=QColor (0,0,0);
+ }
+ p.setColor(QPalette::Active, static_cast(9), c);
+ p.setColor(QPalette::Inactive, static_cast(9), c);
+ e->setPalette(p);
+}
+