bool MainWindow::loadFile(const QString& fileName) { std::string cpath = fileName.toStdString(); auto& factory = DocumentFactory::instance(); auto possibleDocuments = factory.documentsToLoadFile(cpath); std::string selectedDocument; if (possibleDocuments.empty()) { QStringList items; for (const auto& doc : factory.documents()) items.push_back(QString::fromStdString(doc.name)); bool ok = false; QString item = QInputDialog::getItem(this, tr("Unknown file type"), tr("Document type:"), items, 0, false, &ok); if (!ok) return false; selectedDocument = item.toStdString(); } else if (possibleDocuments.size() == 1) { selectedDocument = possibleDocuments.front(); } else { QStringList items; for (const auto& c : possibleDocuments) items.push_back(QString::fromStdString(c)); bool ok = false; QString item = QInputDialog::getItem(this, tr("Choose document type"), tr("Document type:"), items, 0, false, &ok); if (!ok) return false; selectedDocument = item.toStdString(); } auto document = factory.create(selectedDocument); if(!document) { statusBar()->showMessage(tr("Could not create the document"), 2000); return false; } ChangeDir cd(fileName); setDocument(document); if (!document->loadFile(cpath)) { setDocument(nullptr); setCurrentFile(""); statusBar()->showMessage(tr("Loading failed"), 2000); return false; } setCurrentFile(fileName); statusBar()->showMessage(tr("File loaded"), 2000); return true; }
ItemText::ItemText(const QString &text, bool isRichText, QWidget *parent) : QTextEdit(parent) , ItemWidget(this) , m_textDocument() , m_searchTextDocument() , m_textFormat(isRichText ? Qt::RichText : Qt::PlainText) { init(m_textDocument, font()); init(m_searchTextDocument, font()); setUndoRedoEnabled(false); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setFrameStyle(QFrame::NoFrame); // Selecting text copies it to clipboard. connect( this, SIGNAL(selectionChanged()), SLOT(onSelectionChanged()) ); setReadOnly(true); if (isRichText) m_textDocument.setHtml( text.left(defaultMaxBytes) ); else m_textDocument.setPlainText( text.left(defaultMaxBytes) ); setDocument(&m_textDocument); updateSize(); }
TextLayer::TextLayer(const int layer_id , QGraphicsItem *parent , QGraphicsScene *scene ) : QGraphicsItem(parent,scene),evesum(0),modus(Show),border(1.),currentprintrender(false), hi(Metric("30px")),wi(Metric("110px")),bgcolor(QColor(Qt::white)),SwapLockBreak(false), bordercolor(QColor(Qt::red)),Rotate(0),check_view_area_time(0),ActionHover(false), format(DIV_ABSOLUTE),mount(new TextController) { mount->q = this; setAcceptsHoverEvents(true); wisub_border = wi + border; history.clear(); id = layer_id; setAcceptDrops(true); setFlag(QGraphicsItem::ItemIsSelectable,true); setFlag(QGraphicsItem::ItemIsFocusable,true); setFlag(QGraphicsItem::ItemIsMovable,false); setSelected(false); _doc = new QTextDocument(); _doc->setHtml(tr("<p>Write your text<p>")); QTextFrame *Tframe = _doc->rootFrame(); QTextFrameFormat rootformats = Tframe->frameFormat(); rootformats.setWidth(wi); rootformats.setBorder(0); Tframe->setFrameFormat(rootformats); _doc->setPageSize(QSizeF(wi,hi)); DLayout = _doc->documentLayout(); setDocument(_doc); mount->txtControl()->document()->toHtml().size(); /* connect all */ setZValue(1.99999); RestoreMoveAction(); init(); }
void RenderWindow::fileOpen(const QString & filename) { QDomDocument doc; QString errMsg; int errLine, errColm; QFile file(filename); if(!doc.setContent(&file, &errMsg, &errLine, &errColm)) { QMessageBox::critical(this, tr("Error Loading File"), tr("There was an error opening the file %1." "\n\n%2 on line %3 column %4.") .arg(filename).arg(errMsg).arg(errLine).arg(errColm) ); return; } QDomElement root = doc.documentElement(); if(root.tagName() != "report") { QMessageBox::critical(this, tr("Not a Valid File"), tr("The file %1 does not appear to be a valid file." "\n\nThe root node is not 'report'.").arg(filename) ); return; } _report->setText(filename); setDocument(doc); }
PagePreviewWebView::PagePreviewWebView(QWidget* parent) : QWebView(parent) { /* combobox with the html files */ m_combobox = new QComboBox(this); /* verify the type of the doc and update the combobox */ connect(KDevelop::ICore::self()->documentController(), SIGNAL(documentActivated(KDevelop::IDocument*)), SLOT(setDocument(KDevelop::IDocument*))); /* for every change in the combobox, update the combobox */ connect(m_combobox, SIGNAL(currentIndexChanged(int)), SLOT(previewDocumentCombo(int))); //switch on timer m_timer = new QTimer(); m_timer->setSingleShot(true); connect(KDevelop::ICore::self()->documentController(), SIGNAL(documentContentChanged(KDevelop::IDocument*)), SLOT(timerPreview())); //switch off timer connect(m_timer, SIGNAL(timeout()), SLOT(previewDocument())); if(KDevelop::IDocument* doc = KDevelop::ICore::self()->documentController()->activeDocument()){ setDocument(doc); } }
KPrSlidesSorterDocumentModel::KPrSlidesSorterDocumentModel(KPrViewModeSlidesSorter *viewModeSlidesSorter, QWidget *parent, KoPADocument *document) : QAbstractListModel(parent) , m_viewModeSlidesSorter(viewModeSlidesSorter) { setDocument(document); setSupportedDragActions(Qt::MoveAction); }
DocumentListModel::DocumentListModel(Document *d, QObject *parent) : QAbstractListModel(parent) , m_doc(d)/* m_scene(0), m_view(0),*/ , m_iconSize(48,0) , m_sceneRect(0,0,1024,768) , m_dirtyTimer(0) , m_queuedIconGenerationMode(false) { if(!m_blankPixmap) { m_blankPixmap = new QPixmap(48,48 * (1/AppSettings::liveAspectRatio())); m_blankPixmap->fill(Qt::lightGray); QPainter painter(m_blankPixmap); painter.setPen(QPen(Qt::black,1,Qt::DotLine)); painter.drawRect(m_blankPixmap->rect().adjusted(0,0,-1,-1)); painter.end(); } m_blankPixmapRefCount ++; connect(&m_needPixmapTimer, SIGNAL(timeout()), this, SLOT(makePixmaps())); if(m_doc) setDocument(d); if(MainWindow::mw()) { m_sceneRect = MainWindow::mw()->standardSceneRect(); connect(MainWindow::mw(), SIGNAL(aspectRatioChanged(double)), this, SLOT(aspectRatioChanged(double))); } setSceneRect(m_sceneRect); }
/** * Constructs a new JTextArea with the specified number of rows * and columns, and the given model. All of the constructors * feed through this constructor. * * @param doc the model to use, or create a default one if NULL * @param text the text to be displayed, NULL if none * @param rows the number of rows >= 0 * @param columns the number of columns >= 0 * @exception IllegalArgumentException if the rows or columns * arguments are negative. */ /*public*/ JTextArea::JTextArea(Document* doc, QString text, int rows, int columns, QWidget *parent) : QTextEdit(parent){ //super(); common(); this->rows = rows; setColumns(columns); if (doc == NULL) { doc = createDefaultModel(); } else setDocument(doc); if (text != NULL) { setText(text); // select(0, 0); } if (rows < 0) { throw new IllegalArgumentException("rows: " + QString::number(rows)); } if (columns < 0) { throw new IllegalArgumentException("columns: " + QString::number(columns)); } #if 0 LookAndFeel.installProperty(this, "focusTraversalKeysForward", JComponent. getManagingFocusForwardTraversalKeys()); LookAndFeel.installProperty(this, "focusTraversalKeysBackward", JComponent. getManagingFocusBackwardTraversalKeys()); #endif }
// ----------------------------------------------------------------- // Name : detachDocument // ----------------------------------------------------------------- guiTabbedFrame_Document * guiTabbedFrame::detachDocument() { guiDocument * pDoc = guiFrame::unsetDocument(); if (pDoc == NULL) { return NULL; } int size = m_pDocumentsList.size(); if (size < 2) { setDocument(pDoc); return NULL; } guiTabbedFrame_Document * ret = NULL; for (list<guiTabbedFrame_Document*>::iterator it = m_pDocumentsList.begin(); it != m_pDocumentsList.end(); ++it) { if ((*it)->m_pDoc == pDoc) { ret = *it; it = m_pDocumentsList.erase(it); break; } } if (m_pDocumentsList.empty()) { m_pDoc = NULL; } else { setMainDocument((*(m_pDocumentsList.begin()))->m_pDoc); } return ret; }
MdiChild::MdiChild() { _document = new Document(this); docLayout = new PlainTextDocumentLayout(_document); _document->setDocumentLayout(docLayout); setDocument(_document); syntaxHightlighter = new SyntaxHighlighter(_document); syntaxHightlighter->setDocument(_document); setAttribute(Qt::WA_DeleteOnClose); setWindowIcon(QIcon::fromTheme("text-x-generic")); isUntitled = true; autoindent = true; snipples=NULL; snipplesActivateOk=NULL; replaceTabsBySpacesOk = NULL; //setTabStopWidth(20); setCursorWidth(3); connect(document(), SIGNAL(contentsChanged()), this, SLOT(documentContentsChanged())); connect(document(), SIGNAL(modificationChanged(bool)), this, SLOT(documentWasModified())); connect(document(), SIGNAL(fileNameChanged(QString)), this, SLOT(setCurrentFile(QString))); connect(docLayout, SIGNAL(docChanged(int, int, int)), this, SLOT(documentChanged(int, int, int))); }
void ExpandingLabel::setLabelText(const QString& theText) { QTextDocument *doc = new QTextDocument(this); doc->setHtml(theText); setDocument(doc); setToolTip(theText); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); setAlignment(Qt::AlignCenter); setContextMenuPolicy(Qt::NoContextMenu); }
Highlighter::Highlighter(QPlainTextEdit *edit, const QColor &col) : QSyntaxHighlighter(edit), d(new HighlighterPrivate(this, col)) { d->plainTextEdit = edit; setDocument(d->plainTextEdit->document()); d->plainTextEdit->installEventFilter(this); d->plainTextEdit->viewport()->installEventFilter(this); }
void CodeEditorBox::onComboSelectionChanged(int index) { QModelIndex proxyIndex = mProxyModel->index(index, 0); QModelIndex mRow = mProxyModel->mapToSource(proxyIndex); int mIndex = mRow.row(); if(mIndex >=0 && index>=0 && mDocComboBox) { setDocument(Main::documentManager()->docModel()->item(mIndex)->data().value<Document *>(), -1, 0); } }
bool JSON::parse(Variant & root, const std::string & document) { auto tokenizer = createJSONTokenizer(); // Set document tokenizer.setDocument(document); // Begin parsing return readDocument(root, tokenizer); }
bool HRFile::doRead(const std::string & fileName) { if(!HObject::FileIO.open(fileName.c_str(), HDocument::oReadOnly)) { setLatestError(BaseFile::FileNotReadable); return false; } setDocument(HObject::FileIO); return true; }
NodeIteratorImpl::NodeIteratorImpl(NodeImpl *rootNode, long whatToShow, NodeFilterImpl *filter, bool expandEntityReferences) :TraversalImpl(rootNode, whatToShow, filter, expandEntityReferences), m_referenceNode(0), m_beforeReferenceNode(true), m_detached(false), m_doc(0) { if (root()) { setDocument(root()->getDocument()); if (document()) { document()->attachNodeIterator(this); document()->ref(); } } }
void TreeScope::setParentTreeScope(TreeScope& newParentScope) { // A document node cannot be re-parented. ASSERT(!rootNode().isDocumentNode()); newParentScope.guardRef(); if (m_parentTreeScope) m_parentTreeScope->guardDeref(); m_parentTreeScope = &newParentScope; setDocument(newParentScope.document()); }
void ContactBrowser::init( const QContact& contact, ContactDocument::ContactDocumentType docType) { mLink.clear(); if (!mDocument) mDocument = new ContactDocument(this); mDocument->textDocument()->setTextWidth(width() - 10); mDocument->init(this, contact, docType); setDocument(mDocument->textDocument()); loadLinks(contact.customField(QDL::CLIENT_DATA_KEY)); verifyLinks(); }
void ChatEdit::setSession(ChatSessionImpl *session) { m_session = session; setDocument(session->getInputField()); setFocus(); QFont chatEditFont = qApp->font(); Config cfg = Config("appearance"); cfg.beginGroup("chat"); chatEditFont.setPointSize(cfg.value("chatFontSize", qApp->font().pointSize())); cfg.endGroup(); session->getInputField()->setDefaultFont(chatEditFont); }
void ItemText::highlight(const QRegExp &re, const QFont &highlightFont, const QPalette &highlightPalette) { m_searchTextDocument.clear(); if ( re.isEmpty() ) { setDocument(&m_textDocument); } else { bool plain = m_textFormat == Qt::PlainText; const QString &text = plain ? m_textDocument.toPlainText() : m_textDocument.toHtml(); if (plain) m_searchTextDocument.setPlainText(text); else m_searchTextDocument.setHtml(text); QTextCursor cur = m_searchTextDocument.find(re); int a = cur.position(); while ( !cur.isNull() ) { QTextCharFormat fmt = cur.charFormat(); if ( cur.hasSelection() ) { fmt.setBackground( highlightPalette.base() ); fmt.setForeground( highlightPalette.text() ); fmt.setFont(highlightFont); cur.setCharFormat(fmt); } else { cur.movePosition(QTextCursor::NextCharacter); } cur = m_searchTextDocument.find(re, cur); int b = cur.position(); if (a == b) { cur.movePosition(QTextCursor::NextCharacter); cur = m_searchTextDocument.find(re, cur); b = cur.position(); if (a == b) break; } a = b; } setDocument(&m_searchTextDocument); } update(); }
/** * Parses a text document and builds the navigation tree for it */ void NavigationWidget::parse(QTextDocument *document) { const QSignalBlocker blocker(this); Q_UNUSED(blocker); setDocument(document); clear(); _lastHeadingItemList.clear(); for (int i = 0; i < document->blockCount(); i++) { QTextBlock block = document->findBlockByNumber(i); int elementType = block.userState(); // ignore all non headline types if ((elementType < pmh_H1) || (elementType > pmh_H6)) { continue; } QString text = block.text(); text.remove(QRegularExpression("^#+")) .remove(QRegularExpression("#+$")) .remove(QRegularExpression("^\\s+")) .remove(QRegularExpression("^=+$")) .remove(QRegularExpression("^-+$")); if (text.isEmpty()) { continue; } QTreeWidgetItem *item = new QTreeWidgetItem(); item->setText(0, text); item->setData(0, Qt::UserRole, block.position()); item->setToolTip(0, tr("headline %1").arg(elementType - pmh_H1 + 1)); // attempt to find a suitable parent item for the element type QTreeWidgetItem *lastHigherItem = findSuitableParentItem(elementType); if (lastHigherItem == NULL) { // if there wasn't a last higher level item then add the current // item to the top level addTopLevelItem(item); } else { // if there was a last higher level item then add the current // item as child of that item lastHigherItem->addChild(item); } _lastHeadingItemList[elementType] = item; } expandAll(); }
WordTokenizer::WordTokenizer(const Document *pDocument) : Tokenizer(NULL) { string cmdLine("antiword"); // Run antiword Document *pOutputDocument = runHelperProgram(pDocument, cmdLine); if (pOutputDocument != NULL) { // Give the result to the parent class setDocument(pOutputDocument); } }
static void loadDocument(const std::wstring &_fileName) { SyncDocument *newDoc = SyncDocument::load(_fileName); if (newDoc) { // update MRU list mruFileList.insert(_fileName); mruFileList.update(); DrawMenuBar(hwnd); // set new document setDocument(newDoc); setWindowFileName(_fileName.c_str()); } else error("failed to open file"); }
void TestDocumentFileLoadJob::startLoadFromFile() { TestDocumentFileSynchronizer* testSynchronizer = qobject_cast<TestDocumentFileSynchronizer*>( synchronizer() ); TestDocumentFileLoadThread* loadThread = new TestDocumentFileLoadThread( this, testSynchronizer->header(), file() ); loadThread->start(); while( !loadThread->wait(100) ) QApplication::processEvents( QEventLoop::ExcludeUserInputEvents | QEventLoop::ExcludeSocketNotifiers, 100 ); TestDocument* document = loadThread->document(); testSynchronizer->setDocument( document ); delete loadThread; setDocument( document ); }
MLScriptEditor::MLScriptEditor( QWidget* par /*= NULL*/ ) :QPlainTextEdit(par),regexps(),synt(NULL),synhigh(NULL),comp(NULL) { QTextDocument* mydoc = new QTextDocument(this); QPlainTextDocumentLayout* ld = new QPlainTextDocumentLayout(mydoc); mydoc->setDocumentLayout(ld); setDocument(mydoc); narea = new MLNumberArea(this); connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(updateLineNumberAreaWidth(int))); //connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(updateCursorPos(int))); connect(this, SIGNAL(updateRequest(QRect,int)), this, SLOT(updateLineNumberArea(QRect,int))); connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(highlightCurrentLine())); updateLineNumberAreaWidth(0); highlightCurrentLine(); }
BoundTextEdit::BoundTextEdit(QWidget *parent) : QTextEdit(parent) { _model = new TextModelLavaan(this); setDocument(_model); connect(this, &BoundTextEdit::cursorPositionChanged, this, &BoundTextEdit::cursorPositionChangedHandler); connect(_model, &TextModelLavaan::errorStateChanged, this, &BoundTextEdit::errorStateChangedHandler); connect(_model, &TextModelLavaan::contentsChanged, this, &BoundTextEdit::contentsChangedHandler); this->setLineWrapMode(QTextEdit::NoWrap); this->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); this->setAcceptRichText(false); int id = QFontDatabase::addApplicationFont(":/fonts/FiraCode-Retina.ttf"); QString family = QFontDatabase::applicationFontFamilies(id).at(0); QFont font(family); font.setStyleHint(QFont::Monospace); font.setPointSize(10); this->setFont(font); QFontMetrics metrics(font); this->setTabStopWidth(metrics.width(" ") + 2); _errorStylesheet = "padding: 4px; padding-right: 1.5em; background-color: rgba(255,0,0,128); margin-left: 100%;"; _okStylesheet = "padding: 4px; padding-right: 1.5em; margin-left: 100%;"; #ifdef __APPLE__ _okMessage = "\u2318 + Enter to apply"; #else _okMessage = "Ctrl + Enter to apply"; #endif _status = new QLabel(this); _status->setWordWrap(true); _status->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); _status->setAlignment(Qt::AlignBottom | Qt::AlignRight); _status->setStyleSheet(_okStylesheet); _status->setText(_okMessage); _status->setAttribute(Qt::WA_TransparentForMouseEvents); _applied = true; }
DocumentEditor::DocumentEditor(DocumentEditor* document_, QWidget *parent_) : ScintillaExt(parent_), _watcher(document_->_watcher) { _notified = true; //codec setUtf8(true); _codec = document_->_codec; _bomMode = document_->_bomMode; _hasBom = document_->_hasBom; _charsetAutoDetect = document_->_charsetAutoDetect; //document info _autoDetectEol = document_->_autoDetectEol; _autoDetectIndent = document_->_autoDetectIndent; _isNew = document_->isNew(); _fullPath = document_->getFullPath(); setDocument(document_->document()); _clone = document_; _isCloned = true; document_->_clone = this; document_->_isCloned = true; QsciLexer* l = document_->lexer(); if(l != 0) { QString lexLang = l->language(); QsciLexer* newLex = LexerManager::getInstance().lexerFactory(lexLang, this); if(newLex == 0) { //could not find the lexer newLex = LexerManager::getInstance().getAutoLexer(this); } setLexer(newLex); } //macro _macro = new QsciMacro(this); //load settings Settings settings; settings.applyToDocument(this); markerDefine(QPixmap(":/images/ledblue.png").scaled(40,16, Qt::KeepAspectRatio, Qt::SmoothTransformation), MARKER_BOOK); //connection connect(this, SIGNAL(marginClicked(int,int, Qt::KeyboardModifiers)), this, SLOT(toggleBookmark(int,int, Qt::KeyboardModifiers))); }
void MdiChild::setView(MdiChild *mdiChild) { _document = mdiChild->view(); setDocument(_document); bool modified = document()->isModified(); setCurrentFile(_document->fileName()); document()->setModified(modified); isUntitled = mdiChild->isUntitled; setWindowModified(modified); setWindowTitle(userFriendlyCurrentFile() + "[*]"); connect(_document, SIGNAL(contentsChanged()), this, SLOT(documentContentsChanged())); connect(document(), SIGNAL(modificationChanged(bool)), this, SLOT(documentWasModified())); connect(_document, SIGNAL(fileNameChanged(QString)), this, SLOT(setCurrentFile(QString))); }
TEST(DocumentList, NewWaitingCustomEntity) { lc::storage::DocumentList::getInstance().newWaitingCustomEntityEvent().connect<onEventReceived>(); auto doc1 = std::make_shared<lc::storage::DocumentImpl>(std::make_shared<lc::storage::StorageManagerImpl>()); auto customEntityStorage = std::make_shared<lc::meta::CustomEntityStorage>("plugin", "entity", lc::geo::Coordinate()); std::make_shared<lc::operation::AddBlock>(doc1, customEntityStorage)->execute(); auto builder = lc::builder::InsertBuilder(); builder.setDisplayBlock(customEntityStorage); builder.setDocument(doc1); builder.setLayer(std::make_shared<lc::meta::Layer>()); std::make_shared<lc::operation::EntityBuilder>(doc1)->appendEntity(builder.build())->execute(); ASSERT_TRUE(eventReceived); ASSERT_EQ(1, lc::storage::DocumentList::getInstance().waitingCustomEntities("plugin").size()); }
GlslTextEdit::GlslTextEdit(QWidget *parent) : PlainTextWithLineNumberAreaSupport(parent) , m_highlighter(NULL) , m_completer(NULL) , m_lineNumberArea(NULL) , m_gotDocumentAssigned(false) , m_font(new QFont("Consolas, Courier New, Courier", 9)) { m_highlighter = new GlslHighlighter(); m_lineNumberArea = new LineNumberArea(*this); connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(highlightCurrentLine())); highlightCurrentLine(); setDocument(NULL, GLSLT_Undefined); }