NCL Composer  0.1.5
 All Classes Functions Variables Pages
NCLTextEditorMainWindow.cpp
1 /*
2  * Copyright 2011 TeleMidia/PUC-Rio.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library. If not, see
16  * <http://www.gnu.org/licenses/>.
17  */
18 #include <QtGui>
19 
20 #include <Qsci/qsciscintilla.h>
21 
22 #include "NCLTextEditorMainWindow.h"
23 
24 NCLTextEditorMainWindow::NCLTextEditorMainWindow(QWidget *parent):
25  QMainWindow(parent), searchBox(this)
26 {
27  // preferences = new Preferences(parent);
28  createTextView();
29  createActions();
30  createSearchBox();
31 
32 #ifdef NCLEDITOR_STANDALONE
33  createMenus();
34  createToolBars();
35  createOutlineView();
36  createProblemsView();
37  createStatusBar();
38 #endif
39  setDockOptions(NCLTextEditorMainWindow::AllowNestedDocks
40  | NCLTextEditorMainWindow::AllowTabbedDocks
41  | NCLTextEditorMainWindow::AnimatedDocks);
42  // Set window to fixed size
43 #ifndef NCLEDITOR_STANDALONE
44  this->setWindowFlags(Qt::CustomizeWindowHint);//Set window with no title bar
45 #endif
46  // this->setWindowFlags(Qt::FramelessWindowHint); //Set a frameless window
47 
48  /* setTabPosition(Qt::LeftDockWidgetArea, QTabWidget::North);
49  setTabPosition(Qt::RightDockWidgetArea, QTabWidget::North);
50  setTabPosition(Qt::BottomDockWidgetArea, QTabWidget::North);
51  setTabPosition(Qt::TopDockWidgetArea, QTabWidget::North); */
52 
53  readSettings();
54 
55  connect(textEdit, SIGNAL(textChanged()), this, SLOT(documentWasModified()));
56 
57 #ifdef NCLEDITOR_STANDALONE
58  connect ( outlineView, SIGNAL(itemClicked(QTreeWidgetItem*, int)),
59  SLOT(gotoLineOf(QTreeWidgetItem *, int)) );
60 #endif
61 
62  setCurrentFile("");
63  setUnifiedTitleAndToolBarOnMac(true);
64 
65 }
66 
67 void NCLTextEditorMainWindow::closeEvent(QCloseEvent *event)
68 {
69  if (maybeSave()) {
70  writeSettings();
71  event->accept();
72  } else {
73  event->ignore();
74  }
75 }
76 
77 void NCLTextEditorMainWindow::newFile()
78 {
79  if (maybeSave()) {
80  textEdit->clear();
81  setCurrentFile("");
82  }
83 }
84 
85 void NCLTextEditorMainWindow::open()
86 {
87  if (maybeSave()) {
88  QString fileName = QFileDialog::getOpenFileName(this);
89  if (!fileName.isEmpty())
90  loadFile(fileName);
91  }
92 }
93 
94 bool NCLTextEditorMainWindow::save()
95 {
96  if (curFile.isEmpty()) {
97  return saveAs();
98  } else {
99  return saveFile(curFile);
100  }
101 }
102 
103 bool NCLTextEditorMainWindow::saveAs()
104 {
105  QString fileName = QFileDialog::getSaveFileName(this);
106  if (fileName.isEmpty())
107  return false;
108 
109  return saveFile(fileName);
110 }
111 
112 void NCLTextEditorMainWindow::about()
113 {
114  QMessageBox::about(this, tr("About Application"),
115  tr("The <b>Application</b> example demonstrates how to "
116  "write modern GUI applications using Qt, with a menu "
117  "bar, toolbars, and a status bar."));
118 }
119 
120 void NCLTextEditorMainWindow::documentWasModified()
121 {
122  setWindowModified(textEdit->isModified());
123 }
124 
125 void NCLTextEditorMainWindow::createActions()
126 {
127  newAct = new QAction(QIcon(":/images/new.png"), tr("&New"), this);
128  newAct->setShortcut(tr("Ctrl+N"));
129  newAct->setStatusTip(tr("Create a new file"));
130  connect(newAct, SIGNAL(triggered()), this, SLOT(newFile()));
131 
132  openAct = new QAction(QIcon(":/images/open.png"), tr("&Open..."), this);
133  openAct->setShortcut(tr("Ctrl+O"));
134  openAct->setStatusTip(tr("Open an existing file"));
135  connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
136 
137  saveAct = new QAction(QIcon(":/images/save.png"), tr("&Save"), this);
138  saveAct->setShortcut(tr("Ctrl+S"));
139  saveAct->setStatusTip(tr("Save the document to disk"));
140  connect(saveAct, SIGNAL(triggered()), this, SLOT(save()));
141 
142  saveAsAct = new QAction(tr("Save &As..."), this);
143  saveAsAct->setStatusTip(tr("Save the document under a new name"));
144  connect(saveAsAct, SIGNAL(triggered()), this, SLOT(saveAs()));
145 
146  exitAct = new QAction(tr("E&xit"), this);
147  exitAct->setShortcut(tr("Ctrl+Q"));
148  exitAct->setStatusTip(tr("Exit the application"));
149  connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
150 
151  cutAct = new QAction(QIcon(":/images/clipboard_cut.png"), tr("Cu&t"), this);
152  cutAct->setShortcut(tr("Ctrl+X"));
153  cutAct->setStatusTip(tr("Cut the current selection's contents to the "
154  "clipboard"));
155  connect(cutAct, SIGNAL(triggered()), textEdit, SLOT(cut()));
156 
157  copyAct = new QAction(QIcon(":/images/copy.png"), tr("&Copy"), this);
158  copyAct->setShortcut(tr("Ctrl+C"));
159  copyAct->setStatusTip(tr("Copy the current selection's contents to the "
160  "clipboard"));
161  connect(copyAct, SIGNAL(triggered()), textEdit, SLOT(copy()));
162 
163  pasteAct = new QAction(QIcon(":/images/paste.png"), tr("&Paste"), this);
164  pasteAct->setShortcut(tr("Ctrl+V"));
165  pasteAct->setStatusTip(tr("Paste the clipboard's contents into the current "
166  "selection"));
167  connect(pasteAct, SIGNAL(triggered()), textEdit, SLOT(paste()));
168 
169  aboutAct = new QAction(tr("&About"), this);
170  aboutAct->setStatusTip(tr("Show the application's About box"));
171  connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
172 
173  aboutQtAct = new QAction(tr("About &Qt"), this);
174  aboutQtAct->setStatusTip(tr("Show the Qt library's About box"));
175  connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
176 
177  cutAct->setEnabled(false);
178  copyAct->setEnabled(false);
179  connect(textEdit, SIGNAL(copyAvailable(bool)),
180  cutAct, SLOT(setEnabled(bool)));
181  connect(textEdit, SIGNAL(copyAvailable(bool)),
182  copyAct, SLOT(setEnabled(bool)));
183 
184  fullscreenAct = new QAction( QIcon(":/images/window_fullscreen.png"),
185  tr("&FullScreen"), this);
186  fullscreenAct->setShortcut(tr("F11"));
187  fullscreenAct->setStatusTip(tr("Enable/disable fullscreen mode"));
188  connect(fullscreenAct, SIGNAL(triggered()), this, SLOT(showInFullScreen()));
189 
190  editPreferencesAct = new QAction(tr("&Preferences"), this);
191  editPreferencesAct->setStatusTip(tr("Edit Preferences related to "
192  "editors."));
193  connect ( editPreferencesAct, SIGNAL(triggered()),
194  this, SLOT(showPreferences()));
195 
196  synchronizeAct = new QAction ( QIcon(":/images/synchronize-icon-24.png"),
197  tr("&Synchronize"), this);
198  synchronizeAct->setStatusTip(tr("Synchronize current text with the others"
199  " plugins."));
200 
201  showSearchBoxAct = new QAction(QIcon(), tr("Search"), textEdit);
202  showSearchBoxAct->setShortcut(tr("Ctrl+F"));
203  showSearchBoxAct->setShortcutContext(Qt::WindowShortcut);
204  connect(showSearchBoxAct, SIGNAL(triggered()), this, SLOT(showSearchBox()));
205 
206  addAction(showSearchBoxAct);
207 }
208 
209 void NCLTextEditorMainWindow::createMenus()
210 {
211  fileMenu = menuBar()->addMenu(tr("&File"));
212  fileMenu->addAction(newAct);
213  fileMenu->addAction(openAct);
214  fileMenu->addAction(saveAct);
215  fileMenu->addAction(saveAsAct);
216  fileMenu->addSeparator();
217  fileMenu->addAction(exitAct);
218 
219  editMenu = menuBar()->addMenu(tr("&Edit"));
220  editMenu->addAction(cutAct);
221  editMenu->addAction(copyAct);
222  editMenu->addAction(pasteAct);
223  editMenu->addAction(showSearchBoxAct);
224 
225  editMenu->addSeparator();
226  editMenu->addAction(editPreferencesAct);
227 
228  menuBar()->addSeparator();
229 
230  helpMenu = menuBar()->addMenu(tr("&Help"));
231  helpMenu->addAction(aboutAct);
232  helpMenu->addAction(aboutQtAct);
233 }
234 
235 void NCLTextEditorMainWindow::createToolBars()
236 {
237  fileToolBar = addToolBar(tr("File"));
238  fileToolBar->setObjectName(QString("fileToolBar"));
239  fileToolBar->addAction(newAct);
240  fileToolBar->addAction(openAct);
241  fileToolBar->addAction(saveAct);
242  fileToolBar->addAction(fullscreenAct);
243 
244  editToolBar = addToolBar(tr("Edit"));
245  editToolBar->setObjectName(QString("editToolBar"));
246  editToolBar->addAction(cutAct);
247  editToolBar->addAction(copyAct);
248  editToolBar->addAction(pasteAct);
249  editToolBar->addAction(synchronizeAct);
250 }
251 
252 void NCLTextEditorMainWindow::createStatusBar()
253 {
254  statusBar()->showMessage(tr("Ready"));
255 }
256 
257 void NCLTextEditorMainWindow::createOutlineView()
258 {
259 #ifdef NCLEDITOR_STANDALONE
260  outlineView = new NCLTreeWidget(this);
261  //outlineView->setMaximumWidth(300);
262  outlineView->setColumnCount(4);
263  // outlineView->setEditTriggers(QAbstractItemView::AllEditTriggers);
264 
265  dockOutlineView = new QDockWidget("Outline", this);
266  dockOutlineView->setObjectName(QString("dockOutlineView"));
267  dockOutlineView->setFeatures(QDockWidget::DockWidgetMovable /*|
268  QDockWidget::DockWidgetFloatable*/);
269  /* dockOutlineView->setAllowedAreas(Qt::LeftDockWidgetArea |
270  Qt::RightDockWidgetArea); */
271  dockOutlineView->setWidget(outlineView);
272 
273  addDockWidget(Qt::LeftDockWidgetArea, dockOutlineView);
274 
275  outlineView->setContextMenuPolicy(Qt::ActionsContextMenu);
276 
277  nodeMenu = new QMenu(outlineView);
278  insertNodeChildAct = new QAction( QIcon(":/images/save.png"),
279  tr("&Add child"), this);
280  connect ( insertNodeChildAct, SIGNAL(triggered()),
281  this, SLOT(insertElement()));
282 
283  outlineView->addAction(insertNodeChildAct);
284 
285  connect( outlineView,
286  SIGNAL(parserErrorNotify(QString, QString, int, int, int)),
287  textEdit, SLOT(markError(QString, QString, int, int, int)) );
288 #endif
289 }
290 
291 void NCLTextEditorMainWindow::createProblemsView()
292 {
293  problemsView = new NCLProblemsView(this);
294  problemsView->setObjectName(QString("dockProblemsView"));
295  //problemsView->setMaximumHeight(150);
296  addDockWidget(Qt::RightDockWidgetArea, problemsView);
297 
298 #ifdef NCLEDITOR_STANDALONE
299  connect( outlineView,
300  SIGNAL(parserErrorNotify(QString, QString, int, int, int)),
301  problemsView,
302  SLOT(addProblem(QString, QString, int, int, int)));
303 #endif
304 }
305 
306 void NCLTextEditorMainWindow::createSearchBox()
307 {
308  dockSearchBox = new QDockWidget("Search", this);
309  dockSearchBox->setVisible(false);
310  dockSearchBox->setMaximumHeight(65);
311  dockSearchBox->setObjectName(QString("dockSearchBox"));
312  dockSearchBox->setFeatures(QDockWidget::DockWidgetClosable );
313 
314 // doSearchButton.setText(tr("Search"));
315  searchBox.setWindowTitle(tr("Search..."));
316 
317  QGridLayout *layout = new QGridLayout(&searchBox);
318  layout->addWidget(&searchBoxText, 0, 0);
319  // layout->addWidget(&doSearchButton, 0, 1);
320  searchBox.setLayout(layout);
321  layout->setMargin(0);
322 
323  QPushButton *nextButton = new QPushButton(QIcon(":/images/next_icon.png"), "");
324  nextButton->setFlat(true);
325  connect(nextButton, SIGNAL(pressed()), SLOT(findNext()));
326 
327  QPushButton *previousButton = new QPushButton(QIcon(":/images/previous_icon.png"), "");
328  previousButton->setFlat(true);
329  connect(previousButton, SIGNAL(pressed()), SLOT(findPrevious()));
330 
331  nextButton->setMaximumSize(16, 16);
332  previousButton->setMaximumSize(16, 16);
333  layout->addWidget(previousButton, 0, 1);
334  layout->addWidget(nextButton, 0, 2);
335 
336 // connect(&doSearchButton, SIGNAL(pressed()), this, SLOT(findNext()));
337  connect(&searchBoxText, SIGNAL(textChanged(QString)),
338  SLOT(findNext(QString)));
339 
340  connect(&searchBoxText, SIGNAL(returnPressed()), SLOT(findNext()));
341 
342  connect(&searchBoxText, SIGNAL(shiftReturnPressed()), SLOT(findPrevious()));
343 
344  connect(&searchBoxText, SIGNAL(escPressed()), SLOT(hideSearchBox()));
345 
346  dockSearchBox->setWidget(&searchBox);
347  addDockWidget(Qt::RightDockWidgetArea, dockSearchBox);
348 }
349 
350 void NCLTextEditorMainWindow::readSettings()
351 {
352  QSettings settings(QSettings::IniFormat, QSettings::UserScope, "Trolltech", "Application Example");
353  QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
354  QSize size = settings.value("size", QSize(400, 400)).toSize();
355  bool fullscreen = settings.value("fullscreen", true).toBool();
356 
357  resize(size);
358  move(pos);
359 
360  restoreState(settings.value("qDocksState").toByteArray());
361 
362  if(fullscreen)
363  showFullScreen();
364 
365 }
366 
367 void NCLTextEditorMainWindow::writeSettings()
368 {
369  QSettings settings(QSettings::IniFormat, QSettings::UserScope, "Trolltech", "Application Example");
370  settings.setValue("pos", pos());
371  settings.setValue("size", size());
372  settings.setValue("fullscreen", isFullScreen());
373 
374  // Save the QDock position state
375  settings.setValue("qDocksState", saveState());
376 }
377 
378 bool NCLTextEditorMainWindow::maybeSave()
379 {
380  if (textEdit->isModified()) {
381  int ret = QMessageBox::warning(this, tr("Application"),
382  tr("The document has been modified.\n"
383  "Do you want to save your changes?"),
384  QMessageBox::Yes | QMessageBox::Default,
385  QMessageBox::No,
386  QMessageBox::Cancel|QMessageBox::Escape);
387  if (ret == QMessageBox::Yes)
388  return save();
389  else if (ret == QMessageBox::Cancel)
390  return false;
391  }
392  return true;
393 }
394 
395 void NCLTextEditorMainWindow::loadFile(const QString &fileName)
396 {
397  QFile file(fileName);
398  if (!file.open(QFile::ReadOnly)) {
399  QMessageBox::warning(this, tr("Application"),
400  tr("Cannot read file %1:\n%2.")
401  .arg(fileName)
402  .arg(file.errorString()));
403  return;
404  }
405 
406  QTextStream in(&file);
407  QApplication::setOverrideCursor(Qt::WaitCursor);
408  textEdit->setText(in.readAll());
409  QApplication::restoreOverrideCursor();
410 
411  setCurrentFile(fileName);
412  statusBar()->showMessage(tr("File loaded"), 2000);
413 }
414 
415 bool NCLTextEditorMainWindow::saveFile(const QString &fileName)
416 {
417  QFile file(fileName);
418  if (!file.open(QFile::WriteOnly)) {
419  QMessageBox::warning(this, tr("Application"),
420  tr("Cannot write file %1:\n%2.")
421  .arg(fileName)
422  .arg(file.errorString()));
423  return false;
424  }
425 
426  QTextStream out(&file);
427  QApplication::setOverrideCursor(Qt::WaitCursor);
428  out << textEdit->text();
429  QApplication::restoreOverrideCursor();
430 
431  setCurrentFile(fileName);
432  statusBar()->showMessage(tr("File saved"), 2000);
433 #ifdef NCLEDITOR_STANDALONE
434  outlineView->updateFromText(textEdit->text());
435 #endif
436  return true;
437 }
438 
439 void NCLTextEditorMainWindow::setCurrentFile(const QString &fileName)
440 {
441  curFile = fileName;
442  textEdit->setModified(false);
443  setWindowModified(false);
444 
445  QString shownName;
446  if (curFile.isEmpty())
447  shownName = "untitled.txt";
448  else
449  shownName = strippedName(curFile);
450 
451  setWindowTitle(tr("%1[*] - %2").arg(shownName).arg(tr("Application")));
452 
453 #ifdef NCLEDITOR_STANDALONE
454  outlineView->updateFromText(textEdit->text());
455 #endif
456 }
457 
458 QString NCLTextEditorMainWindow::strippedName(const QString &fullFileName)
459 {
460  return QFileInfo(fullFileName).fileName();
461 }
462 
463 void NCLTextEditorMainWindow::showInFullScreen(){
464  if(!isFullScreen())
465  showFullScreen();
466  else
467  showNormal();
468 }
469 
470 void NCLTextEditorMainWindow::gotoLineOf(QTreeWidgetItem *item, int column)
471 {
472  (void) column;
473 
474  bool ok;
475  int line = item->text(2).toInt(&ok, 10);
476  textEdit->setCursorPosition(line-1, 0);
477  textEdit->ensureLineVisible(line-1);
478  textEdit->SendScintilla(QsciScintilla::SCI_SETFOCUS, true);
479 }
480 
481 //FIXME: 1. fix line element line numbers.
482 void NCLTextEditorMainWindow::insertElement()
483 {
484 #ifdef NCLEDITOR_STANDALONE
485  bool ok;
486  QList<QTreeWidgetItem*> selecteds = outlineView->selectedItems ();
487  QTreeWidgetItem *item = selecteds.at (0);
488  QString id = item->text(1);
489  int line = item->text(2).toInt ( &ok, 10 );
490  QString tagname = item->text(0);
491  QMap <QString, QString> empty;
492 
493  QStringList strlist;
494  map <QString, char> * children =
495  NCLStructure::getInstance()->getChildren(tagname);
496 
497  if(children != NULL) {
498  map <QString, char>::iterator it;
499  for(it = children->begin(); it != children->end(); ++it){
500  strlist << it->first;
501  }
502  }
503 
504  QString element = QInputDialog::getItem(this,
505  tr("&Add child"),
506  tr("Element name:"),
507  strlist,
508  0,
509  true,
510  &ok);
511 
512  if(ok && !element.isEmpty())
513  {
514  //Add new Element to OutlineWidget
515  outlineView->addElement(item, 0, element, QString(""), empty, line, 0);
516 
517  //Add new Element to texttWidget
518  int endLine = textEdit
519  ->SendScintilla( QsciScintilla::SCI_GETLINEENDPOSITION,
520  line-1);
521  int beginLine = textEdit
522  ->SendScintilla(QsciScintilla::SCI_POSITIONFROMLINE,
523  line-1);
524  int end_element_column = item->text(3).toInt(&ok, 10);
525  bool fix_next_line_indentation = false;
526 
527  //find if we are in a "<tagname/>" then open this tag
528  char ch = textEdit->SendScintilla(
529  QsciScintilla::SCI_GETCHARAT, beginLine +
530  end_element_column-1);
531  if (ch == '/') {
532  QString endtag = ">";
533  endtag += "<";
534  textEdit->insertAt(tagname, line-1, end_element_column);
535  textEdit->insertAt(endtag, line-1, end_element_column-1);
536  }
537 
538  //put all the required attributes
539  //TODO: remove from here (create a function)
540  map <QString, bool> *attributes =
541  NCLStructure::getInstance()->getAttributes(element);
542  if(attributes != NULL) {
543  map <QString, bool>::iterator it;
544  for(it = attributes->begin(); it != attributes->end(); ++it){
545  if(it->second) {
546  element += " ";
547  element += it->first + "=\"\"";
548  }
549  }
550  }
551 
552  element.prepend("<");
553  element.append("/>");
554  if(end_element_column != endLine-beginLine) {
555  fix_next_line_indentation = true;
556  element.append("\n");
557  }
558 
559  element.prepend("\n");
560 
561  // qDebug() << line << " " << beginLine << " " << endLine << " "
562  // << end_element_column << " ";
563 
564  textEdit->insertAt(element, line-1, end_element_column);
565 
566  //fix indentation
567  int lineident = textEdit->SendScintilla(
568  QsciScintilla::SCI_GETLINEINDENTATION,
569  line-1);
570  textEdit->SendScintilla(QsciScintilla::SCI_GETLINEINDENTATION, line-1);
571 
572  if(fix_next_line_indentation)
573  textEdit->SendScintilla( QsciScintilla::SCI_SETLINEINDENTATION,
574  line+1, lineident);
575 
576  textEdit->SendScintilla(QsciScintilla::SCI_SETLINEINDENTATION,
577  line,
578  lineident+8);
579 
580  textEdit->setCursorPosition(line, 0);
581  textEdit->ensureLineVisible(line);
582  textEdit->SendScintilla(QsciScintilla::SCI_SETFOCUS, true);
583 
584  emit elementAdded(tagname, id, empty, false);
585  }
586 #endif
587 
588 }
589 
590 void NCLTextEditorMainWindow::createTextView() {
591  dockTextEdit = new QDockWidget("Text", this);
592  dockTextEdit->setObjectName(QString("dockTextView"));
593  dockTextEdit->setFeatures(QDockWidget::DockWidgetMovable);
594 
595  //Remove the title bar if whe are working in the plugin version.
596 #ifndef NCLEDITOR_STANDALONE
597  QWidget* titleWidget = new QWidget(this);/*where this a QMainWindow object*/
598  dockTextEdit->setTitleBarWidget( titleWidget );
599 #endif
600 
601 // dockTextEdit2 = new QDockWidget("Text", this);
602 // dockTextEdit2->setObjectName(QString("dockTextView2"));
603 // dockTextEdit2->setFeatures(QDockWidget::DockWidgetMovable /*|
604 // QDockWidget::DockWidgetFloatable*/);
605 
606  // dockTextEdit->setAllowedAreas(Qt::LeftDockWidgetArea |
607  // Qt::RightDockWidgetArea);
608 
609  textEdit = new NCLTextEditor(this);
610  textEdit->setTabBehavior(NCLTextEditor::TAB_BEHAVIOR_NEXT_ATTR);
611  dockTextEdit->setWidget(textEdit);
612 
613 // textEdit2 = new NCLTextEditor(this);
614 // textEdit2->setTabBehavior(NCLTextEditor::TAB_BEHAVIOR_NEXT_ATTR);
615 // dockTextEdit2->setWidget(textEdit2);
616 // textEdit2->setDocument(textEdit->document());
617 
618  addDockWidget(Qt::RightDockWidgetArea, dockTextEdit);
619 // addDockWidget(Qt::RightDockWidgetArea, dockTextEdit2);
620 
621  // setCentralWidget(textEdit);
622 
624  //textEditorPreferencesPage = preferences->addPreferencesPage("Text Editor");
625  //textEditorPreferencesPage->addInputString("teste", "teste");
626 }
627 
628 void NCLTextEditorMainWindow::showPreferences()
629 {
630  //preferences->show();
631 }
632 
633 void NCLTextEditorMainWindow::showSearchBox()
634 {
635  dockSearchBox->show();
636  searchBoxText.setFocus();
637 }
638 
639 void NCLTextEditorMainWindow::hideSearchBox()
640 {
641  dockSearchBox->hide();
642  textEdit->setFocus();
643 }
644 
645 void NCLTextEditorMainWindow::findNext()
646 {
647  QString text = searchBoxText.text();
648  findNext(text);
649 }
650 
651 void NCLTextEditorMainWindow::findNext(QString text)
652 {
653  textEdit->findFirst(text, true, false, true, true);
654 }
655 
656 void NCLTextEditorMainWindow::findPrevious()
657 {
658  QString text = searchBoxText.text();
659  findPrevious(text);
660 }
661 
662 void NCLTextEditorMainWindow::findPrevious(QString text)
663 {
664  int line, index;
665  textEdit->getCursorPosition(&line, &index);
666  index -= text.size();
667  if(index < 0) line--;
668 
669  textEdit->findFirst(text, true, false, true, true, false, line, index);
670 }