void Document::reload(bool prompt) { // Abort if there is no file to reload if (m_index) { return; } // Confirm that they do want to reload if (prompt) { QMessageBox mbox(window()); mbox.setIcon(QMessageBox::Question); mbox.setWindowTitle(tr("Reload File")); mbox.setText(tr("Reload the file %1 from disk?").arg("<i>" + QFileInfo(m_filename).fileName() + "</i>")); mbox.setInformativeText(tr("All unsaved changes will be lost.")); QPushButton* reload_button = mbox.addButton(tr("Reload"), QMessageBox::AcceptRole); if (reload_button->style()->styleHint(QStyle::SH_DialogButtonBox_ButtonsHaveIcons)) { reload_button->setIcon(reload_button->style()->standardIcon(QStyle::SP_BrowserReload)); } mbox.addButton(QMessageBox::Cancel); mbox.setDefaultButton(reload_button); if (mbox.exec() == QMessageBox::Cancel) { return; } } // Reload file emit loadStarted(Window::tr("Opening %1").arg(QDir::toNativeSeparators(m_filename))); m_text->setReadOnly(true); disconnect(m_text->document(), SIGNAL(contentsChange(int,int,int)), this, SLOT(updateWordCount(int,int,int))); disconnect(m_text->document(), SIGNAL(undoCommandAdded()), this, SLOT(undoCommandAdded())); loadFile(m_filename, -1); emit loadFinished(); }
UBGraphicsTextItem::UBGraphicsTextItem(QGraphicsItem * parent) : QGraphicsTextItem(parent) , UBGraphicsItem() , mMultiClickState(0) , mLastMousePressTime(QTime::currentTime()) { setDelegate(new UBGraphicsTextItemDelegate(this, 0)); // TODO claudio remove this because in contrast with the fact the frame should be created on demand. Delegate()->createControls(); Delegate()->frame()->setOperationMode(UBGraphicsDelegateFrame::Resizing); Delegate()->setUBFlag(GF_FLIPPABLE_ALL_AXIS, false); Delegate()->setUBFlag(GF_REVOLVABLE, true); mTypeTextHereLabel = tr("<Type Text Here>"); setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object); setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); //Necessary to set if we want z value to be assigned correctly setFlag(QGraphicsItem::ItemIsSelectable, true); setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); setTextInteractionFlags(Qt::TextEditorInteraction); setUuid(QUuid::createUuid()); connect(document(), SIGNAL(contentsChanged()), Delegate(), SLOT(contentsChanged())); connect(document(), SIGNAL(undoCommandAdded()), this, SLOT(undoCommandAdded())); connect(document()->documentLayout(), SIGNAL(documentSizeChanged(const QSizeF &)), this, SLOT(documentSizeChanged(const QSizeF &))); }
bool Document::loadFile(const QString& filename, int position) { bool loaded = true; if (filename.isEmpty()) { m_text->setReadOnly(false); scrollBarRangeChanged(m_scrollbar->minimum(), m_scrollbar->maximum()); calculateWordCount(); connect(m_text->document(), SIGNAL(contentsChange(int,int,int)), this, SLOT(updateWordCount(int,int,int))); connect(m_text->document(), SIGNAL(undoCommandAdded()), this, SLOT(undoCommandAdded())); return loaded; }
void MaxQTextDocument::doConnections() { connect(document, SIGNAL(blockCountChanged(int)), SLOT(onBlockCountChanged(int))); connect(document, SIGNAL(contentsChange(int, int, int)), SLOT(onContentsChange(int, int, int))); connect(document, SIGNAL(contentsChanged()), SLOT(onContentsChanged())); connect(document, SIGNAL(cursorPositionChanged(const QTextCursor &)), SLOT(onCursorPositionChanged(const QTextCursor &))); connect(document, SIGNAL(documentLayoutChanged()), SLOT(onDocumentLayoutChanged())); connect(document, SIGNAL(modificationChanged(bool)), SLOT(onModificationChanged(bool))); connect(document, SIGNAL(redoAvailable(bool)), SLOT(onRedoAvailable(bool))); connect(document, SIGNAL(undoAvailable(bool)), SLOT(onUndoAvailable(bool))); connect(document, SIGNAL(undoCommandAdded()), SLOT(onUndoCommandAdded())); }
UBGraphicsTextItem::UBGraphicsTextItem(QGraphicsItem * parent) : QGraphicsTextItem(parent) , mDelegate(0) , mMultiClickState(0) , mLastMousePressTime(QTime::currentTime()) { mDelegate = new UBGraphicsTextItemDelegate(this, 0); mDelegate->init(); mDelegate->frame()->setOperationMode(UBGraphicsDelegateFrame::Resizing); mTypeTextHereLabel = tr("<Type Text Here>"); if (lastUsedTextColor.isValid()) { setDefaultTextColor(lastUsedTextColor); setColorOnDarkBackground(lastUsedTextColor); setColorOnLightBackground(lastUsedTextColor); } else { QColor colorOnDarkBG = UBApplication::boardController->penColorOnDarkBackground(); QColor colorOnLightBG = UBApplication::boardController->penColorOnLightBackground(); setColorOnDarkBackground(colorOnDarkBG); setColorOnLightBackground(colorOnLightBG); } setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object); setFlag(QGraphicsItem::ItemIsSelectable, true); setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); setTextInteractionFlags(Qt::TextEditorInteraction); connect(document(), SIGNAL(contentsChanged()), mDelegate, SLOT(contentsChanged())); connect(document(), SIGNAL(undoCommandAdded()), this, SLOT(undoCommandAdded())); connect(document()->documentLayout(), SIGNAL(documentSizeChanged(const QSizeF &)), this, SLOT(documentSizeChanged(const QSizeF &))); }
UBGraphicsTextItem::UBGraphicsTextItem(QGraphicsItem * parent) : QGraphicsTextItem(parent) , UBGraphicsItem() , mMultiClickState(0) , mLastMousePressTime(QTime::currentTime()) { setDelegate(new UBGraphicsTextItemDelegate(this, 0)); Delegate()->init(); Delegate()->frame()->setOperationMode(UBGraphicsDelegateFrame::Resizing); Delegate()->setFlippable(false); Delegate()->setRotatable(true); mTypeTextHereLabel = tr("<Type Text Here>"); setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object); // setData(UBGraphicsItemData::ItemEditable, QVariant(true)); setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); //Necessary to set if we want z value to be assigned correctly setFlag(QGraphicsItem::ItemIsSelectable, true); // setFlag(QGraphicsItem::ItemIsMovable, true); setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); setTextInteractionFlags(Qt::TextEditorInteraction); setUuid(QUuid::createUuid()); connect(document(), SIGNAL(contentsChanged()), Delegate(), SLOT(contentsChanged())); connect(document(), SIGNAL(undoCommandAdded()), this, SLOT(undoCommandAdded())); connect(document()->documentLayout(), SIGNAL(documentSizeChanged(const QSizeF &)), this, SLOT(documentSizeChanged(const QSizeF &))); }
/** * @brief Constructor. * @param file_path Path of the file to open. * @param editor The parent object. */ TextEditorWidget::TextEditorWidget(const QString& file_path, TextEditor& editor): QPlainTextEdit(file_path, &editor), line_number_area(new LineNumberArea(*this)), undo_stack(editor.get_undo_stack()), tab_length(2), replace_tab_by_spaces(false) { // Undo/redo system. connect(document(), SIGNAL(undoCommandAdded()), this, SLOT(undo_command_added())); // Line number displaying. connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(update_line_number_area_width(int))); connect(this, SIGNAL(updateRequest(const QRect&, int)), this, SLOT(update_line_number_area(const QRect&, int))); connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(highlight_current_line())); update_line_number_area_width(0); highlight_current_line(); }
Document::Document(const QString& filename, int& current_wordcount, int& current_time, const QString& theme, QWidget* parent) : QWidget(parent), m_index(0), m_always_center(false), m_rich_text(false), m_cached_block_count(-1), m_cached_current_block(-1), m_page_type(0), m_page_amount(0), m_accurate_wordcount(true), m_current_wordcount(current_wordcount), m_current_time(current_time) { setMouseTracking(true); m_stats = &m_document_stats; m_hide_timer = new QTimer(this); m_hide_timer->setInterval(5000); m_hide_timer->setSingleShot(true); connect(m_hide_timer, SIGNAL(timeout()), this, SLOT(hideMouse())); // Set up text area m_text = new Editor(this); m_text->installEventFilter(this); m_text->setMouseTracking(true); m_text->setFrameStyle(QFrame::NoFrame); m_text->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); m_text->viewport()->setMouseTracking(true); m_text->viewport()->installEventFilter(this); QTextDocument* document = new QTextDocument(m_text); document->setUndoRedoEnabled(false); // Read file bool unknown_rich_text = false; if (!filename.isEmpty()) { m_rich_text = isRichTextFile(filename.toLower()); m_filename = QFileInfo(filename).canonicalFilePath(); updateState(); if (!m_rich_text) { QFile file(filename); if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { QTextStream stream(&file); stream.setCodec(QTextCodec::codecForName("UTF-8")); stream.setAutoDetectUnicode(true); QTextCursor cursor(document); while (!stream.atEnd()) { cursor.insertText(stream.read(8192)); QApplication::processEvents(); } file.close(); } } else { PROSEUP::Reader reader; reader.read(filename, document); if (reader.hasError()) { QMessageBox::warning(this, tr("Sorry"), reader.errorString()); } } } // Set text area contents document->setUndoRedoEnabled(true); document->setModified(false); m_text->setDocument(document); m_text->setTabStopWidth(50); document->setIndentWidth(50); m_dictionary = new Dictionary(this); m_highlighter = new Highlighter(m_text, m_dictionary); connect(m_dictionary, SIGNAL(changed()), this, SLOT(dictionaryChanged())); if (m_filename.isEmpty()) { findIndex(); unknown_rich_text = true; } else { m_text->setReadOnly(!QFileInfo(m_filename).isWritable()); } // Set up scroll bar m_text->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); m_scrollbar = m_text->verticalScrollBar(); m_scrollbar->setPalette(QApplication::palette()); m_scrollbar->setAutoFillBackground(true); m_scrollbar->setVisible(false); connect(m_scrollbar, SIGNAL(actionTriggered(int)), this, SLOT(scrollBarActionTriggered(int))); connect(m_scrollbar, SIGNAL(rangeChanged(int,int)), this, SLOT(scrollBarRangeChanged(int,int))); scrollBarRangeChanged(m_scrollbar->minimum(), m_scrollbar->maximum()); // Lay out window m_layout = new QGridLayout(this); m_layout->setSpacing(0); m_layout->setMargin(0); m_layout->addWidget(m_text, 0, 1); m_layout->addWidget(m_scrollbar, 0, 2, Qt::AlignRight); // Load settings Preferences preferences; if (unknown_rich_text) { m_rich_text = preferences.richText(); } m_text->setAcceptRichText(m_rich_text); loadPreferences(preferences); loadTheme(theme); if(m_rich_text) { m_text->setUndoRedoEnabled(false); cleanUpDocument(); m_text->setUndoRedoEnabled(true); m_text->document()->setModified(false); } calculateWordCount(); connect(m_text->document(), SIGNAL(undoCommandAdded()), this, SLOT(undoCommandAdded())); connect(m_text->document(), SIGNAL(contentsChange(int,int,int)), this, SLOT(updateWordCount(int,int,int))); connect(m_text, SIGNAL(cursorPositionChanged()), this, SLOT(cursorPositionChanged())); connect(m_text, SIGNAL(selectionChanged()), this, SLOT(selectionChanged())); }
Document::Document(const QString& filename, int& current_wordcount, int& current_time, QWidget* parent) : QWidget(parent), m_cache_filename(randomCacheFilename()), m_index(0), m_always_center(false), m_rich_text(false), m_cached_block_count(-1), m_cached_current_block(-1), m_page_type(0), m_page_amount(0), m_accurate_wordcount(true), m_current_wordcount(current_wordcount), m_current_time(current_time) { setMouseTracking(true); m_stats = &m_document_stats; m_hide_timer = new QTimer(this); m_hide_timer->setInterval(5000); m_hide_timer->setSingleShot(true); connect(m_hide_timer, SIGNAL(timeout()), this, SLOT(hideMouse())); // Set up text area m_text = new QTextEdit(this); m_text->installEventFilter(this); m_text->setMouseTracking(true); m_text->setFrameStyle(QFrame::NoFrame); m_text->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); m_text->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); m_text->setTabStopWidth(50); m_text->document()->setIndentWidth(50); m_text->horizontalScrollBar()->setAttribute(Qt::WA_NoMousePropagation); m_text->viewport()->setMouseTracking(true); m_text->viewport()->installEventFilter(this); connect(m_text, SIGNAL(cursorPositionChanged()), this, SLOT(cursorPositionChanged())); connect(m_text, SIGNAL(selectionChanged()), this, SLOT(selectionChanged())); connect(m_text->document(), SIGNAL(undoCommandAdded()), this, SLOT(undoCommandAdded())); connect(m_text->document(), SIGNAL(contentsChange(int,int,int)), this, SLOT(updateWordCount(int,int,int))); m_dictionary = new Dictionary(this); m_highlighter = new Highlighter(m_text, m_dictionary); m_focusmode = new FocusMode(m_text); connect(m_dictionary, SIGNAL(changed()), this, SLOT(dictionaryChanged())); // Set filename bool unknown_rich_text = false; if (!filename.isEmpty()) { m_rich_text = isRichTextFile(filename.toLower()); m_filename = QFileInfo(filename).canonicalFilePath(); updateState(); } if (m_filename.isEmpty()) { findIndex(); unknown_rich_text = true; } else { m_text->setReadOnly(!QFileInfo(m_filename).isWritable()); } // Set up scroll bar m_scrollbar = m_text->verticalScrollBar(); m_scrollbar->setAttribute(Qt::WA_NoMousePropagation); m_scrollbar->setPalette(QApplication::palette()); m_scrollbar->setAutoFillBackground(true); m_scrollbar->setMouseTracking(true); m_scrollbar->installEventFilter(this); setScrollBarVisible(false); connect(m_scrollbar, SIGNAL(actionTriggered(int)), this, SLOT(scrollBarActionTriggered(int))); connect(m_scrollbar, SIGNAL(rangeChanged(int,int)), this, SLOT(scrollBarRangeChanged(int,int))); // Lay out window m_layout = new QGridLayout(this); m_layout->setSpacing(0); m_layout->setMargin(0); m_layout->addWidget(m_text, 0, 1); m_layout->addWidget(m_scrollbar, 0, 2, Qt::AlignRight); // Load settings Preferences preferences; if (unknown_rich_text) { m_rich_text = preferences.richText(); } m_text->setAcceptRichText(m_rich_text); loadPreferences(preferences); }
int QTextDocument::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QObject::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: contentsChange((*reinterpret_cast< int(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2])),(*reinterpret_cast< int(*)>(_a[3]))); break; case 1: contentsChanged(); break; case 2: undoAvailable((*reinterpret_cast< bool(*)>(_a[1]))); break; case 3: redoAvailable((*reinterpret_cast< bool(*)>(_a[1]))); break; case 4: undoCommandAdded(); break; case 5: modificationChanged((*reinterpret_cast< bool(*)>(_a[1]))); break; case 6: cursorPositionChanged((*reinterpret_cast< const QTextCursor(*)>(_a[1]))); break; case 7: blockCountChanged((*reinterpret_cast< int(*)>(_a[1]))); break; case 8: documentLayoutChanged(); break; case 9: undo(); break; case 10: redo(); break; case 11: appendUndoItem((*reinterpret_cast< QAbstractUndoItem*(*)>(_a[1]))); break; case 12: setModified((*reinterpret_cast< bool(*)>(_a[1]))); break; case 13: setModified(); break; } _id -= 14; } #ifndef QT_NO_PROPERTIES else if (_c == QMetaObject::ReadProperty) { void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< bool*>(_v) = isUndoRedoEnabled(); break; case 1: *reinterpret_cast< bool*>(_v) = isModified(); break; case 2: *reinterpret_cast< QSizeF*>(_v) = pageSize(); break; case 3: *reinterpret_cast< QFont*>(_v) = defaultFont(); break; case 4: *reinterpret_cast< bool*>(_v) = useDesignMetrics(); break; case 5: *reinterpret_cast< QSizeF*>(_v) = size(); break; case 6: *reinterpret_cast< qreal*>(_v) = textWidth(); break; case 7: *reinterpret_cast< int*>(_v) = blockCount(); break; case 8: *reinterpret_cast< qreal*>(_v) = indentWidth(); break; case 9: *reinterpret_cast< QString*>(_v) = defaultStyleSheet(); break; case 10: *reinterpret_cast< int*>(_v) = maximumBlockCount(); break; } _id -= 11; } else if (_c == QMetaObject::WriteProperty) { void *_v = _a[0]; switch (_id) { case 0: setUndoRedoEnabled(*reinterpret_cast< bool*>(_v)); break; case 1: setModified(*reinterpret_cast< bool*>(_v)); break; case 2: setPageSize(*reinterpret_cast< QSizeF*>(_v)); break; case 3: setDefaultFont(*reinterpret_cast< QFont*>(_v)); break; case 4: setUseDesignMetrics(*reinterpret_cast< bool*>(_v)); break; case 6: setTextWidth(*reinterpret_cast< qreal*>(_v)); break; case 8: setIndentWidth(*reinterpret_cast< qreal*>(_v)); break; case 9: setDefaultStyleSheet(*reinterpret_cast< QString*>(_v)); break; case 10: setMaximumBlockCount(*reinterpret_cast< int*>(_v)); break; } _id -= 11; } else if (_c == QMetaObject::ResetProperty) { _id -= 11; } else if (_c == QMetaObject::QueryPropertyDesignable) { _id -= 11; } else if (_c == QMetaObject::QueryPropertyScriptable) { _id -= 11; } else if (_c == QMetaObject::QueryPropertyStored) { _id -= 11; } else if (_c == QMetaObject::QueryPropertyEditable) { _id -= 11; } else if (_c == QMetaObject::QueryPropertyUser) { _id -= 11; } #endif // QT_NO_PROPERTIES return _id; }