-rw-r--r-- | noncore/apps/opie-write/mainwindow.cpp | 24 | ||||
-rw-r--r-- | noncore/apps/opie-write/qtextedit.cpp | 4 |
2 files changed, 14 insertions, 14 deletions
diff --git a/noncore/apps/opie-write/mainwindow.cpp b/noncore/apps/opie-write/mainwindow.cpp index 6bb524f..90e1a70 100644 --- a/noncore/apps/opie-write/mainwindow.cpp +++ b/noncore/apps/opie-write/mainwindow.cpp | |||
@@ -30,345 +30,345 @@ | |||
30 | #include <qaction.h> | 30 | #include <qaction.h> |
31 | #include <qtoolbar.h> | 31 | #include <qtoolbar.h> |
32 | #include <qtoolbutton.h> | 32 | #include <qtoolbutton.h> |
33 | #include <qtabwidget.h> | 33 | #include <qtabwidget.h> |
34 | #include <qapplication.h> | 34 | #include <qapplication.h> |
35 | #include <qfontdatabase.h> | 35 | #include <qfontdatabase.h> |
36 | #include <qcombobox.h> | 36 | #include <qcombobox.h> |
37 | #include <qlineedit.h> | 37 | #include <qlineedit.h> |
38 | #include <qfileinfo.h> | 38 | #include <qfileinfo.h> |
39 | #include <qfile.h> | 39 | #include <qfile.h> |
40 | #include <qfiledialog.h> | 40 | #include <qfiledialog.h> |
41 | #include <qprinter.h> | 41 | #include <qprinter.h> |
42 | #include <qpaintdevicemetrics.h> | 42 | #include <qpaintdevicemetrics.h> |
43 | #include <qmenubar.h> | 43 | #include <qmenubar.h> |
44 | #include <qpopupmenu.h> | 44 | #include <qpopupmenu.h> |
45 | #include <qcolordialog.h> | 45 | #include <qcolordialog.h> |
46 | #include <qpainter.h> | 46 | #include <qpainter.h> |
47 | #include <qstyle.h> | 47 | #include <qstyle.h> |
48 | 48 | ||
49 | class ButtonMenu : public QToolButton | 49 | class ButtonMenu : public QToolButton |
50 | { | 50 | { |
51 | Q_OBJECT | 51 | Q_OBJECT |
52 | public: | 52 | public: |
53 | ButtonMenu( QWidget *parent, const char *name=0 ) | 53 | ButtonMenu( QWidget *parent, const char *name=0 ) |
54 | : QToolButton( parent, name ), current(0) | 54 | : QToolButton( parent, name ), current(0) |
55 | { | 55 | { |
56 | setPopup( new QPopupMenu( this ) ); | 56 | setPopup( new QPopupMenu( this ) ); |
57 | setPopupDelay( 1 ); | 57 | setPopupDelay( 1 ); |
58 | connect( popup(), SIGNAL(activated(int)), this, SLOT(selected(int)) ); | 58 | connect( popup(), SIGNAL(activated(int)), this, SLOT(selected(int)) ); |
59 | } | 59 | } |
60 | 60 | ||
61 | int insertItem(const QIconSet &icon, const QString &text, int id ) { | 61 | int insertItem(const QIconSet &icon, const QString &text, int id ) { |
62 | if ( !popup()->count() ) { | 62 | if ( !popup()->count() ) { |
63 | setIconSet( icon ); | 63 | setIconSet( icon ); |
64 | current = id; | 64 | current = id; |
65 | } | 65 | } |
66 | return popup()->insertItem( icon, text, id ); | 66 | return popup()->insertItem( icon, text, id ); |
67 | } | 67 | } |
68 | 68 | ||
69 | void setCurrentItem( int id ) { | 69 | void setCurrentItem( int id ) { |
70 | if ( id != current ) { | 70 | if ( id != current ) { |
71 | current = id; | 71 | current = id; |
72 | setIconSet( *popup()->iconSet( id ) ); | 72 | setIconSet( *popup()->iconSet( id ) ); |
73 | } | 73 | } |
74 | } | 74 | } |
75 | 75 | ||
76 | virtual QSize sizeHint() const { | 76 | virtual QSize sizeHint() const { |
77 | return QToolButton::sizeHint() + QSize( 4, 0 ); | 77 | return QToolButton::sizeHint() + QSize( 4, 0 ); |
78 | } | 78 | } |
79 | 79 | ||
80 | signals: | 80 | signals: |
81 | void activated( int id ); | 81 | void activated( int id ); |
82 | 82 | ||
83 | protected slots: | 83 | protected slots: |
84 | void selected( int id ) { | 84 | void selected( int id ) { |
85 | current = id; | 85 | current = id; |
86 | setIconSet( *popup()->iconSet( id ) ); | 86 | setIconSet( *popup()->iconSet( id ) ); |
87 | emit activated( id ); | 87 | emit activated( id ); |
88 | } | 88 | } |
89 | 89 | ||
90 | protected: | 90 | protected: |
91 | virtual void drawButtonLabel( QPainter *p ) { | 91 | virtual void drawButtonLabel( QPainter *p ) { |
92 | p->translate( -4, 0 ); | 92 | p->translate( -4, 0 ); |
93 | QToolButton::drawButtonLabel( p ); | 93 | QToolButton::drawButtonLabel( p ); |
94 | p->translate( 4, 0 ); | 94 | p->translate( 4, 0 ); |
95 | } | 95 | } |
96 | 96 | ||
97 | private: | 97 | private: |
98 | int current; | 98 | int current; |
99 | }; | 99 | }; |
100 | 100 | ||
101 | //=========================================================================== | 101 | //=========================================================================== |
102 | 102 | ||
103 | MainWindow::MainWindow( QWidget *parent, const char *name, WFlags fl ) | 103 | MainWindow::MainWindow( QWidget *parent, const char *name, WFlags fl ) |
104 | : QMainWindow( parent, name, fl ), | 104 | : QMainWindow( parent, name, fl ), |
105 | doc( 0 ) | 105 | doc( 0 ) |
106 | { | 106 | { |
107 | setRightJustification(TRUE); | 107 | setRightJustification(TRUE); |
108 | 108 | ||
109 | editorStack = new QWidgetStack( this ); | 109 | editorStack = new QWidgetStack( this ); |
110 | 110 | ||
111 | fileSelector = new FileSelector( "text/html", | 111 | fileSelector = new FileSelector( "text/html", |
112 | editorStack, "fileselector" ); | 112 | editorStack, "fileselector" ); |
113 | 113 | ||
114 | 114 | ||
115 | fileSelector->setCloseVisible( FALSE ); | 115 | fileSelector->setCloseVisible( FALSE ); |
116 | editorStack->addWidget( fileSelector, 0 ); | 116 | editorStack->addWidget( fileSelector, 0 ); |
117 | 117 | ||
118 | editor = new Qt3::QTextEdit( editorStack ); | 118 | editor = new Qt3::QTextEdit( editorStack ); |
119 | editor->setTextFormat( Qt::RichText ); | 119 | editor->setTextFormat( Qt::RichText ); |
120 | editorStack->addWidget( editor, 1 ); | 120 | editorStack->addWidget( editor, 1 ); |
121 | 121 | ||
122 | setupActions(); | 122 | setupActions(); |
123 | 123 | ||
124 | QObject::connect( fileSelector, SIGNAL(closeMe()), | 124 | QObject::connect( fileSelector, SIGNAL(closeMe()), |
125 | this, SLOT(showEditTools()) ); | 125 | this, SLOT(showEditTools()) ); |
126 | QObject::connect( fileSelector, SIGNAL(fileSelected(const DocLnk &)), | 126 | QObject::connect( fileSelector, SIGNAL(fileSelected(const DocLnk&)), |
127 | this, SLOT(openFile(const DocLnk &)) ); | 127 | this, SLOT(openFile(const DocLnk&)) ); |
128 | QObject::connect( fileSelector, SIGNAL(newSelected(const DocLnk&)), | 128 | QObject::connect( fileSelector, SIGNAL(newSelected(const DocLnk&)), |
129 | this, SLOT(newFile(const DocLnk&)) ); | 129 | this, SLOT(newFile(const DocLnk&)) ); |
130 | 130 | ||
131 | if ( fileSelector->fileCount() < 1 ) | 131 | if ( fileSelector->fileCount() < 1 ) |
132 | fileNew(); | 132 | fileNew(); |
133 | else { | 133 | else { |
134 | fileOpen(); | 134 | fileOpen(); |
135 | } | 135 | } |
136 | doConnections( editor ); | 136 | doConnections( editor ); |
137 | 137 | ||
138 | setCentralWidget( editorStack ); | 138 | setCentralWidget( editorStack ); |
139 | } | 139 | } |
140 | 140 | ||
141 | MainWindow::~MainWindow() | 141 | MainWindow::~MainWindow() |
142 | { | 142 | { |
143 | save(); | 143 | save(); |
144 | } | 144 | } |
145 | 145 | ||
146 | void MainWindow::setupActions() | 146 | void MainWindow::setupActions() |
147 | { | 147 | { |
148 | setToolBarsMovable(false); | 148 | setToolBarsMovable(false); |
149 | 149 | ||
150 | tbMenu = new QToolBar( this ); | 150 | tbMenu = new QToolBar( this ); |
151 | tbMenu->setHorizontalStretchable( TRUE ); | 151 | tbMenu->setHorizontalStretchable( TRUE ); |
152 | 152 | ||
153 | QMenuBar *menu = new QMenuBar( tbMenu ); | 153 | QMenuBar *menu = new QMenuBar( tbMenu ); |
154 | 154 | ||
155 | tbEdit = new QToolBar( this ); | 155 | tbEdit = new QToolBar( this ); |
156 | 156 | ||
157 | QPopupMenu *file = new QPopupMenu( this ); | 157 | QPopupMenu *file = new QPopupMenu( this ); |
158 | menu->insertItem( tr("File"), file ); | 158 | menu->insertItem( tr("File"), file ); |
159 | 159 | ||
160 | QPopupMenu *edit = new QPopupMenu( this ); | 160 | QPopupMenu *edit = new QPopupMenu( this ); |
161 | menu->insertItem( tr("Edit"), edit ); | 161 | menu->insertItem( tr("Edit"), edit ); |
162 | 162 | ||
163 | // ### perhaps these shortcut keys should have some | 163 | // ### perhaps these shortcut keys should have some |
164 | // IPaq keys defined??? | 164 | // IPaq keys defined??? |
165 | QAction *a; | 165 | QAction *a; |
166 | 166 | ||
167 | a = new QAction( tr( "New" ), Resource::loadPixmap("new"), QString::null, 0, this, 0 ); | 167 | a = new QAction( tr( "New" ), Resource::loadPixmap("new"), QString::null, 0, this, 0 ); |
168 | connect( a, SIGNAL(activated()), this, SLOT(fileNew()) ); | 168 | connect( a, SIGNAL(activated()), this, SLOT(fileNew()) ); |
169 | a->addTo( file ); | 169 | a->addTo( file ); |
170 | 170 | ||
171 | a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); | 171 | a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); |
172 | connect( a, SIGNAL(activated()), this, SLOT(fileOpen()) ); | 172 | connect( a, SIGNAL(activated()), this, SLOT(fileOpen()) ); |
173 | a->addTo( file ); | 173 | a->addTo( file ); |
174 | 174 | ||
175 | a = new QAction( tr( "Undo" ), Resource::loadIconSet("undo"), | 175 | a = new QAction( tr( "Undo" ), Resource::loadIconSet("undo"), |
176 | QString::null, 0, this, "editUndo" ); | 176 | QString::null, 0, this, "editUndo" ); |
177 | connect( a, SIGNAL( activated() ), this, SLOT( editUndo() ) ); | 177 | connect( a, SIGNAL( activated() ), this, SLOT( editUndo() ) ); |
178 | connect( editor, SIGNAL(undoAvailable(bool)), a, SLOT(setEnabled(bool)) ); | 178 | connect( editor, SIGNAL(undoAvailable(bool)), a, SLOT(setEnabled(bool)) ); |
179 | a->addTo( tbEdit ); | 179 | a->addTo( tbEdit ); |
180 | a->addTo( edit ); | 180 | a->addTo( edit ); |
181 | a = new QAction( tr( "Redo" ), Resource::loadIconSet("redo"), | 181 | a = new QAction( tr( "Redo" ), Resource::loadIconSet("redo"), |
182 | QString::null, 0, this, "editRedo" ); | 182 | QString::null, 0, this, "editRedo" ); |
183 | connect( a, SIGNAL( activated() ), this, SLOT( editRedo() ) ); | 183 | connect( a, SIGNAL( activated() ), this, SLOT( editRedo() ) ); |
184 | connect( editor, SIGNAL(redoAvailable(bool)), a, SLOT(setEnabled(bool)) ); | 184 | connect( editor, SIGNAL(redoAvailable(bool)), a, SLOT(setEnabled(bool)) ); |
185 | a->addTo( tbEdit ); | 185 | a->addTo( tbEdit ); |
186 | a->addTo( edit ); | 186 | a->addTo( edit ); |
187 | 187 | ||
188 | edit->insertSeparator(); | 188 | edit->insertSeparator(); |
189 | 189 | ||
190 | a = new QAction( tr( "Copy" ), Resource::loadIconSet("copy"), | 190 | a = new QAction( tr( "Copy" ), Resource::loadIconSet("copy"), |
191 | QString::null, 0, this, "editCopy" ); | 191 | QString::null, 0, this, "editCopy" ); |
192 | connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) ); | 192 | connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) ); |
193 | connect( editor, SIGNAL(copyAvailable(bool)), a, SLOT(setEnabled(bool)) ); | 193 | connect( editor, SIGNAL(copyAvailable(bool)), a, SLOT(setEnabled(bool)) ); |
194 | a->addTo( tbEdit ); | 194 | a->addTo( tbEdit ); |
195 | a->addTo( edit ); | 195 | a->addTo( edit ); |
196 | a = new QAction( tr( "Cut" ), Resource::loadIconSet("cut"), | 196 | a = new QAction( tr( "Cut" ), Resource::loadIconSet("cut"), |
197 | QString::null, 0, this, "editCut" ); | 197 | QString::null, 0, this, "editCut" ); |
198 | connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); | 198 | connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); |
199 | connect( editor, SIGNAL(copyAvailable(bool)), a, SLOT(setEnabled(bool)) ); | 199 | connect( editor, SIGNAL(copyAvailable(bool)), a, SLOT(setEnabled(bool)) ); |
200 | a->addTo( tbEdit ); | 200 | a->addTo( tbEdit ); |
201 | a->addTo( edit ); | 201 | a->addTo( edit ); |
202 | a = new QAction( tr( "Paste" ), Resource::loadPixmap("paste"), | 202 | a = new QAction( tr( "Paste" ), Resource::loadPixmap("paste"), |
203 | QString::null, 0, this, "editPaste" ); | 203 | QString::null, 0, this, "editPaste" ); |
204 | connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); | 204 | connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); |
205 | a->addTo( tbEdit ); | 205 | a->addTo( tbEdit ); |
206 | a->addTo( edit ); | 206 | a->addTo( edit ); |
207 | 207 | ||
208 | tbFont = new QToolBar( this ); | 208 | tbFont = new QToolBar( this ); |
209 | tbFont->setLabel( "Font Actions" ); | 209 | tbFont->setLabel( "Font Actions" ); |
210 | tbFont->setHorizontalStretchable(TRUE); | 210 | tbFont->setHorizontalStretchable(TRUE); |
211 | 211 | ||
212 | comboFont = new QComboBox( FALSE, tbFont ); | 212 | comboFont = new QComboBox( FALSE, tbFont ); |
213 | FontDatabase db; | 213 | FontDatabase db; |
214 | QStringList f= db.families(); | 214 | QStringList f= db.families(); |
215 | comboFont->insertStringList( db.families() ); | 215 | comboFont->insertStringList( db.families() ); |
216 | connect( comboFont, SIGNAL( activated( const QString & ) ), | 216 | connect( comboFont, SIGNAL( activated(const QString&) ), |
217 | this, SLOT( textFamily( const QString & ) ) ); | 217 | this, SLOT( textFamily(const QString&) ) ); |
218 | comboFont->setCurrentItem( comboFont->listBox()->index( comboFont->listBox()->findItem( QApplication::font().family() ) ) ); | 218 | comboFont->setCurrentItem( comboFont->listBox()->index( comboFont->listBox()->findItem( QApplication::font().family() ) ) ); |
219 | comboFont->setMaximumWidth(90); | 219 | comboFont->setMaximumWidth(90); |
220 | 220 | ||
221 | comboSize = new QComboBox( TRUE, tbFont ); | 221 | comboSize = new QComboBox( TRUE, tbFont ); |
222 | QValueList<int> sizes = db.standardSizes(); | 222 | QValueList<int> sizes = db.standardSizes(); |
223 | QValueList<int>::Iterator it = sizes.begin(); | 223 | QValueList<int>::Iterator it = sizes.begin(); |
224 | for ( ; it != sizes.end(); ++it ) | 224 | for ( ; it != sizes.end(); ++it ) |
225 | comboSize->insertItem( QString::number( *it ) ); | 225 | comboSize->insertItem( QString::number( *it ) ); |
226 | connect( comboSize, SIGNAL( activated( const QString & ) ), | 226 | connect( comboSize, SIGNAL( activated(const QString&) ), |
227 | this, SLOT( textSize( const QString & ) ) ); | 227 | this, SLOT( textSize(const QString&) ) ); |
228 | comboSize->lineEdit()->setText( QString::number( QApplication::font().pointSize() ) ); | 228 | comboSize->lineEdit()->setText( QString::number( QApplication::font().pointSize() ) ); |
229 | comboSize->setFixedWidth( 38 ); | 229 | comboSize->setFixedWidth( 38 ); |
230 | 230 | ||
231 | tbStyle = new QToolBar( this ); | 231 | tbStyle = new QToolBar( this ); |
232 | tbStyle->setLabel( "Style Actions" ); | 232 | tbStyle->setLabel( "Style Actions" ); |
233 | 233 | ||
234 | actionTextBold = new QAction( tr( "Bold" ), | 234 | actionTextBold = new QAction( tr( "Bold" ), |
235 | Resource::loadPixmap("bold"), | 235 | Resource::loadPixmap("bold"), |
236 | QString::null, CTRL + Key_B, | 236 | QString::null, CTRL + Key_B, |
237 | this, "textBold" ); | 237 | this, "textBold" ); |
238 | connect( actionTextBold, SIGNAL( activated() ), this, SLOT( textBold() ) ); | 238 | connect( actionTextBold, SIGNAL( activated() ), this, SLOT( textBold() ) ); |
239 | actionTextBold->addTo( tbStyle ); | 239 | actionTextBold->addTo( tbStyle ); |
240 | actionTextBold->setToggleAction( TRUE ); | 240 | actionTextBold->setToggleAction( TRUE ); |
241 | actionTextItalic = new QAction( tr( "Italic" ), | 241 | actionTextItalic = new QAction( tr( "Italic" ), |
242 | Resource::loadPixmap("italic"), | 242 | Resource::loadPixmap("italic"), |
243 | tr( "&Italic" ), CTRL + Key_I, | 243 | tr( "&Italic" ), CTRL + Key_I, |
244 | this, "textItalic" ); | 244 | this, "textItalic" ); |
245 | connect( actionTextItalic, SIGNAL( activated() ), this, | 245 | connect( actionTextItalic, SIGNAL( activated() ), this, |
246 | SLOT( textItalic() ) ); | 246 | SLOT( textItalic() ) ); |
247 | actionTextItalic->addTo( tbStyle ); | 247 | actionTextItalic->addTo( tbStyle ); |
248 | actionTextItalic->setToggleAction( TRUE ); | 248 | actionTextItalic->setToggleAction( TRUE ); |
249 | actionTextUnderline = new QAction( tr( "Underline" ), | 249 | actionTextUnderline = new QAction( tr( "Underline" ), |
250 | Resource::loadPixmap("underline"), | 250 | Resource::loadPixmap("underline"), |
251 | tr( "&Underline" ), CTRL + Key_U, | 251 | tr( "&Underline" ), CTRL + Key_U, |
252 | this, "textUnderline" ); | 252 | this, "textUnderline" ); |
253 | connect( actionTextUnderline, SIGNAL( activated() ), | 253 | connect( actionTextUnderline, SIGNAL( activated() ), |
254 | this, SLOT( textUnderline() ) ); | 254 | this, SLOT( textUnderline() ) ); |
255 | actionTextUnderline->addTo( tbStyle ); | 255 | actionTextUnderline->addTo( tbStyle ); |
256 | actionTextUnderline->setToggleAction( TRUE ); | 256 | actionTextUnderline->setToggleAction( TRUE ); |
257 | 257 | ||
258 | alignMenu = new ButtonMenu( tbStyle ); | 258 | alignMenu = new ButtonMenu( tbStyle ); |
259 | alignMenu->insertItem( Resource::loadPixmap("left"), tr("Left"), AlignLeft ); | 259 | alignMenu->insertItem( Resource::loadPixmap("left"), tr("Left"), AlignLeft ); |
260 | alignMenu->insertItem( Resource::loadPixmap("center"), tr("Center"), AlignCenter ); | 260 | alignMenu->insertItem( Resource::loadPixmap("center"), tr("Center"), AlignCenter ); |
261 | alignMenu->insertItem( Resource::loadPixmap("right"), tr("Right"), AlignRight ); | 261 | alignMenu->insertItem( Resource::loadPixmap("right"), tr("Right"), AlignRight ); |
262 | alignMenu->insertItem( Resource::loadPixmap("opie-write/justify"), tr("Full"), Qt3::AlignJustify ); | 262 | alignMenu->insertItem( Resource::loadPixmap("opie-write/justify"), tr("Full"), Qt3::AlignJustify ); |
263 | connect( alignMenu, SIGNAL(activated(int)), this, SLOT(textAlign(int)) ); | 263 | connect( alignMenu, SIGNAL(activated(int)), this, SLOT(textAlign(int)) ); |
264 | } | 264 | } |
265 | 265 | ||
266 | Qt3::QTextEdit *MainWindow::currentEditor() const | 266 | Qt3::QTextEdit *MainWindow::currentEditor() const |
267 | { | 267 | { |
268 | return editor; | 268 | return editor; |
269 | } | 269 | } |
270 | 270 | ||
271 | void MainWindow::doConnections( Qt3::QTextEdit *e ) | 271 | void MainWindow::doConnections( Qt3::QTextEdit *e ) |
272 | { | 272 | { |
273 | connect( e, SIGNAL( currentFontChanged( const QFont & ) ), | 273 | connect( e, SIGNAL( currentFontChanged(const QFont&) ), |
274 | this, SLOT( fontChanged( const QFont & ) ) ); | 274 | this, SLOT( fontChanged(const QFont&) ) ); |
275 | connect( e, SIGNAL( currentColorChanged( const QColor & ) ), | 275 | connect( e, SIGNAL( currentColorChanged(const QColor&) ), |
276 | this, SLOT( colorChanged( const QColor & ) ) ); | 276 | this, SLOT( colorChanged(const QColor&) ) ); |
277 | connect( e, SIGNAL( currentAlignmentChanged( int ) ), | 277 | connect( e, SIGNAL( currentAlignmentChanged(int) ), |
278 | this, SLOT( alignmentChanged( int ) ) ); | 278 | this, SLOT( alignmentChanged(int) ) ); |
279 | } | 279 | } |
280 | 280 | ||
281 | void MainWindow::updateFontSizeCombo( const QFont &f ) | 281 | void MainWindow::updateFontSizeCombo( const QFont &f ) |
282 | { | 282 | { |
283 | comboSize->clear(); | 283 | comboSize->clear(); |
284 | FontDatabase fdb; | 284 | FontDatabase fdb; |
285 | QValueList<int> sizes = fdb.pointSizes( f.family() ); | 285 | QValueList<int> sizes = fdb.pointSizes( f.family() ); |
286 | QValueList<int>::Iterator it = sizes.begin(); | 286 | QValueList<int>::Iterator it = sizes.begin(); |
287 | for ( ; it != sizes.end(); ++it ) | 287 | for ( ; it != sizes.end(); ++it ) |
288 | comboSize->insertItem( QString::number( *it ) ); | 288 | comboSize->insertItem( QString::number( *it ) ); |
289 | } | 289 | } |
290 | 290 | ||
291 | void MainWindow::editUndo() | 291 | void MainWindow::editUndo() |
292 | { | 292 | { |
293 | if ( !currentEditor() ) | 293 | if ( !currentEditor() ) |
294 | return; | 294 | return; |
295 | currentEditor()->undo(); | 295 | currentEditor()->undo(); |
296 | } | 296 | } |
297 | 297 | ||
298 | void MainWindow::editRedo() | 298 | void MainWindow::editRedo() |
299 | { | 299 | { |
300 | if ( !currentEditor() ) | 300 | if ( !currentEditor() ) |
301 | return; | 301 | return; |
302 | currentEditor()->redo(); | 302 | currentEditor()->redo(); |
303 | } | 303 | } |
304 | 304 | ||
305 | void MainWindow::editCut() | 305 | void MainWindow::editCut() |
306 | { | 306 | { |
307 | if ( !currentEditor() ) | 307 | if ( !currentEditor() ) |
308 | return; | 308 | return; |
309 | currentEditor()->cut(); | 309 | currentEditor()->cut(); |
310 | } | 310 | } |
311 | 311 | ||
312 | void MainWindow::editCopy() | 312 | void MainWindow::editCopy() |
313 | { | 313 | { |
314 | if ( !currentEditor() ) | 314 | if ( !currentEditor() ) |
315 | return; | 315 | return; |
316 | currentEditor()->copy(); | 316 | currentEditor()->copy(); |
317 | } | 317 | } |
318 | 318 | ||
319 | void MainWindow::editPaste() | 319 | void MainWindow::editPaste() |
320 | { | 320 | { |
321 | if ( !currentEditor() ) | 321 | if ( !currentEditor() ) |
322 | return; | 322 | return; |
323 | currentEditor()->paste(); | 323 | currentEditor()->paste(); |
324 | } | 324 | } |
325 | 325 | ||
326 | void MainWindow::textBold() | 326 | void MainWindow::textBold() |
327 | { | 327 | { |
328 | if ( !currentEditor() ) | 328 | if ( !currentEditor() ) |
329 | return; | 329 | return; |
330 | currentEditor()->setBold( actionTextBold->isOn() ); | 330 | currentEditor()->setBold( actionTextBold->isOn() ); |
331 | } | 331 | } |
332 | 332 | ||
333 | void MainWindow::textUnderline() | 333 | void MainWindow::textUnderline() |
334 | { | 334 | { |
335 | if ( !currentEditor() ) | 335 | if ( !currentEditor() ) |
336 | return; | 336 | return; |
337 | currentEditor()->setUnderline( actionTextUnderline->isOn() ); | 337 | currentEditor()->setUnderline( actionTextUnderline->isOn() ); |
338 | } | 338 | } |
339 | 339 | ||
340 | void MainWindow::textItalic() | 340 | void MainWindow::textItalic() |
341 | { | 341 | { |
342 | if ( !currentEditor() ) | 342 | if ( !currentEditor() ) |
343 | return; | 343 | return; |
344 | currentEditor()->setItalic( actionTextItalic->isOn() ); | 344 | currentEditor()->setItalic( actionTextItalic->isOn() ); |
345 | } | 345 | } |
346 | 346 | ||
347 | void MainWindow::textFamily( const QString &f ) | 347 | void MainWindow::textFamily( const QString &f ) |
348 | { | 348 | { |
349 | if ( !currentEditor() ) | 349 | if ( !currentEditor() ) |
350 | return; | 350 | return; |
351 | currentEditor()->setFamily( f ); | 351 | currentEditor()->setFamily( f ); |
352 | currentEditor()->viewport()->setFocus(); | 352 | currentEditor()->viewport()->setFocus(); |
353 | } | 353 | } |
354 | 354 | ||
355 | void MainWindow::textSize( const QString &p ) | 355 | void MainWindow::textSize( const QString &p ) |
356 | { | 356 | { |
357 | if ( !currentEditor() ) | 357 | if ( !currentEditor() ) |
358 | return; | 358 | return; |
359 | currentEditor()->setPointSize( p.toInt() ); | 359 | currentEditor()->setPointSize( p.toInt() ); |
360 | currentEditor()->viewport()->setFocus(); | 360 | currentEditor()->viewport()->setFocus(); |
361 | } | 361 | } |
362 | 362 | ||
363 | void MainWindow::textStyle( int i ) | 363 | void MainWindow::textStyle( int i ) |
364 | { | 364 | { |
365 | if ( !currentEditor() ) | 365 | if ( !currentEditor() ) |
366 | return; | 366 | return; |
367 | if ( i == 0 ) | 367 | if ( i == 0 ) |
368 | currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayBlock, | 368 | currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayBlock, |
369 | Qt3::QStyleSheetItem::ListDisc ); | 369 | Qt3::QStyleSheetItem::ListDisc ); |
370 | else if ( i == 1 ) | 370 | else if ( i == 1 ) |
371 | currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayListItem, | 371 | currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayListItem, |
372 | Qt3::QStyleSheetItem::ListDisc ); | 372 | Qt3::QStyleSheetItem::ListDisc ); |
373 | else if ( i == 2 ) | 373 | else if ( i == 2 ) |
374 | currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayListItem, | 374 | currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayListItem, |
diff --git a/noncore/apps/opie-write/qtextedit.cpp b/noncore/apps/opie-write/qtextedit.cpp index 27dd515..73b7b7b 100644 --- a/noncore/apps/opie-write/qtextedit.cpp +++ b/noncore/apps/opie-write/qtextedit.cpp | |||
@@ -584,194 +584,194 @@ static bool block_set_alignment = FALSE; | |||
584 | 584 | ||
585 | The new alignment is \a a. | 585 | The new alignment is \a a. |
586 | 586 | ||
587 | \sa setAlignment() | 587 | \sa setAlignment() |
588 | */ | 588 | */ |
589 | 589 | ||
590 | /*! \fn void QTextEdit::cursorPositionChanged( QTextCursor *c ) | 590 | /*! \fn void QTextEdit::cursorPositionChanged( QTextCursor *c ) |
591 | 591 | ||
592 | This signal is emitted if the position of the cursor changed. \a c | 592 | This signal is emitted if the position of the cursor changed. \a c |
593 | points to the text cursor object. | 593 | points to the text cursor object. |
594 | 594 | ||
595 | \sa setCursorPosition() | 595 | \sa setCursorPosition() |
596 | */ | 596 | */ |
597 | 597 | ||
598 | /*! \overload void QTextEdit::cursorPositionChanged( int para, int pos ) | 598 | /*! \overload void QTextEdit::cursorPositionChanged( int para, int pos ) |
599 | 599 | ||
600 | This signal is emitted if the position of the cursor changed. \a | 600 | This signal is emitted if the position of the cursor changed. \a |
601 | para contains the paragraph index and \a pos contains the character | 601 | para contains the paragraph index and \a pos contains the character |
602 | position within the paragraph. | 602 | position within the paragraph. |
603 | 603 | ||
604 | \sa setCursorPosition() | 604 | \sa setCursorPosition() |
605 | */ | 605 | */ |
606 | 606 | ||
607 | /*! \fn void QTextEdit::returnPressed() | 607 | /*! \fn void QTextEdit::returnPressed() |
608 | 608 | ||
609 | This signal is emitted if the user pressed the Return or the Enter key. | 609 | This signal is emitted if the user pressed the Return or the Enter key. |
610 | */ | 610 | */ |
611 | 611 | ||
612 | /*! | 612 | /*! |
613 | \fn QTextCursor *QTextEdit::textCursor() const | 613 | \fn QTextCursor *QTextEdit::textCursor() const |
614 | 614 | ||
615 | Returns the text edit's text cursor. | 615 | Returns the text edit's text cursor. |
616 | 616 | ||
617 | \warning QTextCursor is not in the public API, but in special | 617 | \warning QTextCursor is not in the public API, but in special |
618 | circumstances you might wish to use it. | 618 | circumstances you might wish to use it. |
619 | */ | 619 | */ |
620 | 620 | ||
621 | /*! Constructs an empty QTextEdit with parent \a parent and name \a | 621 | /*! Constructs an empty QTextEdit with parent \a parent and name \a |
622 | name. | 622 | name. |
623 | */ | 623 | */ |
624 | 624 | ||
625 | QTextEdit::QTextEdit( QWidget *parent, const char *name ) | 625 | QTextEdit::QTextEdit( QWidget *parent, const char *name ) |
626 | : QScrollView( parent, name, WStaticContents | WRepaintNoErase | WResizeNoErase ), | 626 | : QScrollView( parent, name, WStaticContents | WRepaintNoErase | WResizeNoErase ), |
627 | doc( new QTextDocument( 0 ) ), undoRedoInfo( doc ) | 627 | doc( new QTextDocument( 0 ) ), undoRedoInfo( doc ) |
628 | { | 628 | { |
629 | init(); | 629 | init(); |
630 | } | 630 | } |
631 | 631 | ||
632 | /*! | 632 | /*! |
633 | Constructs a QTextEdit with parent \a parent and name \a name. The | 633 | Constructs a QTextEdit with parent \a parent and name \a name. The |
634 | text edit will display the text \a text using context \a context. | 634 | text edit will display the text \a text using context \a context. |
635 | 635 | ||
636 | The \a context is a path which the text edit's QMimeSourceFactory | 636 | The \a context is a path which the text edit's QMimeSourceFactory |
637 | uses to resolve the locations of files and images. It is passed to | 637 | uses to resolve the locations of files and images. It is passed to |
638 | the mimeSourceFactory() when quering data. | 638 | the mimeSourceFactory() when quering data. |
639 | 639 | ||
640 | For example if the text contains an image tag, | 640 | For example if the text contains an image tag, |
641 | \c{<img src="image.png">}, and the context is "path/to/look/in", the | 641 | \c{<img src="image.png">}, and the context is "path/to/look/in", the |
642 | QMimeSourceFactory will try to load the image from | 642 | QMimeSourceFactory will try to load the image from |
643 | "path/to/look/in/image.png". If the tag was | 643 | "path/to/look/in/image.png". If the tag was |
644 | \c{<img src="/image.png">}, the context will not be used (because | 644 | \c{<img src="/image.png">}, the context will not be used (because |
645 | QMimeSourceFactory recognizes that we have used an absolute path) | 645 | QMimeSourceFactory recognizes that we have used an absolute path) |
646 | and will try to load "/image.png". The context is applied in exactly | 646 | and will try to load "/image.png". The context is applied in exactly |
647 | the same way to \e hrefs, for example, | 647 | the same way to \e hrefs, for example, |
648 | \c{<a href="target.html">Target</a>}, would resolve to | 648 | \c{<a href="target.html">Target</a>}, would resolve to |
649 | "path/to/look/in/target.html". | 649 | "path/to/look/in/target.html". |
650 | 650 | ||
651 | */ | 651 | */ |
652 | 652 | ||
653 | QTextEdit::QTextEdit( const QString& text, const QString& context, | 653 | QTextEdit::QTextEdit( const QString& text, const QString& context, |
654 | QWidget *parent, const char *name) | 654 | QWidget *parent, const char *name) |
655 | : QScrollView( parent, name, WStaticContents | WRepaintNoErase | WResizeNoErase ), | 655 | : QScrollView( parent, name, WStaticContents | WRepaintNoErase | WResizeNoErase ), |
656 | doc( new QTextDocument( 0 ) ), undoRedoInfo( doc ) | 656 | doc( new QTextDocument( 0 ) ), undoRedoInfo( doc ) |
657 | { | 657 | { |
658 | init(); | 658 | init(); |
659 | setText( text, context ); | 659 | setText( text, context ); |
660 | } | 660 | } |
661 | 661 | ||
662 | /*! \reimp */ | 662 | /*! \reimp */ |
663 | 663 | ||
664 | QTextEdit::~QTextEdit() | 664 | QTextEdit::~QTextEdit() |
665 | { | 665 | { |
666 | delete undoRedoInfo.d; | 666 | delete undoRedoInfo.d; |
667 | undoRedoInfo.d = 0; | 667 | undoRedoInfo.d = 0; |
668 | delete cursor; | 668 | delete cursor; |
669 | delete doc; | 669 | delete doc; |
670 | delete d; | 670 | delete d; |
671 | } | 671 | } |
672 | 672 | ||
673 | void QTextEdit::init() | 673 | void QTextEdit::init() |
674 | { | 674 | { |
675 | setFrameStyle( Sunken ); | 675 | setFrameStyle( Sunken ); |
676 | undoEnabled = TRUE; | 676 | undoEnabled = TRUE; |
677 | readonly = TRUE; | 677 | readonly = TRUE; |
678 | setReadOnly( FALSE ); | 678 | setReadOnly( FALSE ); |
679 | d = new QTextEditPrivate; | 679 | d = new QTextEditPrivate; |
680 | connect( doc, SIGNAL( minimumWidthChanged( int ) ), | 680 | connect( doc, SIGNAL( minimumWidthChanged(int) ), |
681 | this, SLOT( documentWidthChanged( int ) ) ); | 681 | this, SLOT( documentWidthChanged(int) ) ); |
682 | 682 | ||
683 | mousePressed = FALSE; | 683 | mousePressed = FALSE; |
684 | inDoubleClick = FALSE; | 684 | inDoubleClick = FALSE; |
685 | modified = FALSE; | 685 | modified = FALSE; |
686 | onLink = QString::null; | 686 | onLink = QString::null; |
687 | overWrite = FALSE; | 687 | overWrite = FALSE; |
688 | wrapMode = WidgetWidth; | 688 | wrapMode = WidgetWidth; |
689 | wrapWidth = -1; | 689 | wrapWidth = -1; |
690 | wPolicy = AtWhiteSpace; | 690 | wPolicy = AtWhiteSpace; |
691 | inDnD = FALSE; | 691 | inDnD = FALSE; |
692 | 692 | ||
693 | doc->setFormatter( new QTextFormatterBreakWords ); | 693 | doc->setFormatter( new QTextFormatterBreakWords ); |
694 | doc->formatCollection()->defaultFormat()->setFont( QScrollView::font() ); | 694 | doc->formatCollection()->defaultFormat()->setFont( QScrollView::font() ); |
695 | doc->formatCollection()->defaultFormat()->setColor( colorGroup().color( QColorGroup::Text ) ); | 695 | doc->formatCollection()->defaultFormat()->setColor( colorGroup().color( QColorGroup::Text ) ); |
696 | currentFormat = doc->formatCollection()->defaultFormat(); | 696 | currentFormat = doc->formatCollection()->defaultFormat(); |
697 | currentAlignment = Qt3::AlignAuto; | 697 | currentAlignment = Qt3::AlignAuto; |
698 | 698 | ||
699 | viewport()->setBackgroundMode( PaletteBase ); | 699 | viewport()->setBackgroundMode( PaletteBase ); |
700 | viewport()->setAcceptDrops( TRUE ); | 700 | viewport()->setAcceptDrops( TRUE ); |
701 | resizeContents( 0, doc->lastParagraph() ? | 701 | resizeContents( 0, doc->lastParagraph() ? |
702 | ( doc->lastParagraph()->paragId() + 1 ) * doc->formatCollection()->defaultFormat()->height() : 0 ); | 702 | ( doc->lastParagraph()->paragId() + 1 ) * doc->formatCollection()->defaultFormat()->height() : 0 ); |
703 | 703 | ||
704 | setKeyCompression( TRUE ); | 704 | setKeyCompression( TRUE ); |
705 | viewport()->setMouseTracking( TRUE ); | 705 | viewport()->setMouseTracking( TRUE ); |
706 | #ifndef QT_NO_CURSOR | 706 | #ifndef QT_NO_CURSOR |
707 | viewport()->setCursor( isReadOnly() ? arrowCursor : ibeamCursor ); | 707 | viewport()->setCursor( isReadOnly() ? arrowCursor : ibeamCursor ); |
708 | #endif | 708 | #endif |
709 | cursor = new QTextCursor( doc ); | 709 | cursor = new QTextCursor( doc ); |
710 | 710 | ||
711 | formatTimer = new QTimer( this ); | 711 | formatTimer = new QTimer( this ); |
712 | connect( formatTimer, SIGNAL( timeout() ), | 712 | connect( formatTimer, SIGNAL( timeout() ), |
713 | this, SLOT( formatMore() ) ); | 713 | this, SLOT( formatMore() ) ); |
714 | lastFormatted = doc->firstParagraph(); | 714 | lastFormatted = doc->firstParagraph(); |
715 | 715 | ||
716 | scrollTimer = new QTimer( this ); | 716 | scrollTimer = new QTimer( this ); |
717 | connect( scrollTimer, SIGNAL( timeout() ), | 717 | connect( scrollTimer, SIGNAL( timeout() ), |
718 | this, SLOT( autoScrollTimerDone() ) ); | 718 | this, SLOT( autoScrollTimerDone() ) ); |
719 | 719 | ||
720 | interval = 0; | 720 | interval = 0; |
721 | changeIntervalTimer = new QTimer( this ); | 721 | changeIntervalTimer = new QTimer( this ); |
722 | connect( changeIntervalTimer, SIGNAL( timeout() ), | 722 | connect( changeIntervalTimer, SIGNAL( timeout() ), |
723 | this, SLOT( doChangeInterval() ) ); | 723 | this, SLOT( doChangeInterval() ) ); |
724 | 724 | ||
725 | cursorVisible = TRUE; | 725 | cursorVisible = TRUE; |
726 | blinkTimer = new QTimer( this ); | 726 | blinkTimer = new QTimer( this ); |
727 | connect( blinkTimer, SIGNAL( timeout() ), | 727 | connect( blinkTimer, SIGNAL( timeout() ), |
728 | this, SLOT( blinkCursor() ) ); | 728 | this, SLOT( blinkCursor() ) ); |
729 | 729 | ||
730 | #ifndef QT_NO_DRAGANDDROP | 730 | #ifndef QT_NO_DRAGANDDROP |
731 | dragStartTimer = new QTimer( this ); | 731 | dragStartTimer = new QTimer( this ); |
732 | connect( dragStartTimer, SIGNAL( timeout() ), | 732 | connect( dragStartTimer, SIGNAL( timeout() ), |
733 | this, SLOT( startDrag() ) ); | 733 | this, SLOT( startDrag() ) ); |
734 | #endif | 734 | #endif |
735 | 735 | ||
736 | 736 | ||
737 | formatMore(); | 737 | formatMore(); |
738 | 738 | ||
739 | blinkCursorVisible = FALSE; | 739 | blinkCursorVisible = FALSE; |
740 | 740 | ||
741 | viewport()->setFocusProxy( this ); | 741 | viewport()->setFocusProxy( this ); |
742 | viewport()->setFocusPolicy( WheelFocus ); | 742 | viewport()->setFocusPolicy( WheelFocus ); |
743 | viewport()->installEventFilter( this ); | 743 | viewport()->installEventFilter( this ); |
744 | installEventFilter( this ); | 744 | installEventFilter( this ); |
745 | } | 745 | } |
746 | 746 | ||
747 | void QTextEdit::paintDocument( bool drawAll, QPainter *p, int cx, int cy, int cw, int ch ) | 747 | void QTextEdit::paintDocument( bool drawAll, QPainter *p, int cx, int cy, int cw, int ch ) |
748 | { | 748 | { |
749 | bool drawCur = hasFocus() || viewport()->hasFocus(); | 749 | bool drawCur = hasFocus() || viewport()->hasFocus(); |
750 | if ( hasSelectedText() || isReadOnly() || !cursorVisible ) | 750 | if ( hasSelectedText() || isReadOnly() || !cursorVisible ) |
751 | drawCur = FALSE; | 751 | drawCur = FALSE; |
752 | QColorGroup g = colorGroup(); | 752 | QColorGroup g = colorGroup(); |
753 | if ( doc->paper() ) | 753 | if ( doc->paper() ) |
754 | g.setBrush( QColorGroup::Base, *doc->paper() ); | 754 | g.setBrush( QColorGroup::Base, *doc->paper() ); |
755 | 755 | ||
756 | if ( contentsY() < doc->y() ) { | 756 | if ( contentsY() < doc->y() ) { |
757 | p->fillRect( contentsX(), contentsY(), visibleWidth(), doc->y(), | 757 | p->fillRect( contentsX(), contentsY(), visibleWidth(), doc->y(), |
758 | g.brush( QColorGroup::Base ) ); | 758 | g.brush( QColorGroup::Base ) ); |
759 | } | 759 | } |
760 | if ( drawAll && doc->width() - contentsX() < cx + cw ) { | 760 | if ( drawAll && doc->width() - contentsX() < cx + cw ) { |
761 | p->fillRect( doc->width() - contentsX(), cy, cx + cw - doc->width() + contentsX(), ch, | 761 | p->fillRect( doc->width() - contentsX(), cy, cx + cw - doc->width() + contentsX(), ch, |
762 | g.brush( QColorGroup::Base ) ); | 762 | g.brush( QColorGroup::Base ) ); |
763 | } | 763 | } |
764 | 764 | ||
765 | p->setBrushOrigin( -contentsX(), -contentsY() ); | 765 | p->setBrushOrigin( -contentsX(), -contentsY() ); |
766 | 766 | ||
767 | lastFormatted = doc->draw( p, cx, cy, cw, ch, g, !drawAll, drawCur, cursor ); | 767 | lastFormatted = doc->draw( p, cx, cy, cw, ch, g, !drawAll, drawCur, cursor ); |
768 | 768 | ||
769 | if ( lastFormatted == doc->lastParagraph() ) | 769 | if ( lastFormatted == doc->lastParagraph() ) |
770 | resizeContents( contentsWidth(), doc->height() ); | 770 | resizeContents( contentsWidth(), doc->height() ); |
771 | 771 | ||
772 | if ( contentsHeight() < visibleHeight() && ( !doc->lastParagraph() || doc->lastParagraph()->isValid() ) && drawAll ) | 772 | if ( contentsHeight() < visibleHeight() && ( !doc->lastParagraph() || doc->lastParagraph()->isValid() ) && drawAll ) |
773 | p->fillRect( 0, contentsHeight(), visibleWidth(), | 773 | p->fillRect( 0, contentsHeight(), visibleWidth(), |
774 | visibleHeight() - contentsHeight(), g.brush( QColorGroup::Base ) ); | 774 | visibleHeight() - contentsHeight(), g.brush( QColorGroup::Base ) ); |
775 | } | 775 | } |
776 | 776 | ||
777 | /*! \reimp */ | 777 | /*! \reimp */ |