コード例 #1
0
ファイル: vdirectorytree.cpp プロジェクト: vscanf/vnote
void VDirectoryTree::pasteDirectoriesFromClipboard()
{
    if (!pasteAvailable()) {
        return;
    }

    QJsonObject obj = VUtils::clipboardToJson();
    QJsonArray dirs = obj[ClipboardConfig::c_dirs].toArray();
    bool isCut = obj[ClipboardConfig::c_isCut].toBool();
    QVector<QString> dirsToPaste(dirs.size());
    for (int i = 0; i < dirs.size(); ++i) {
        dirsToPaste[i] = dirs[i].toString();
    }

    VDirectory *destDir;
    QTreeWidgetItem *item = currentItem();
    if (item) {
        destDir = getVDirectory(item);
    } else {
        destDir = m_notebook->getRootDir();
    }

    pasteDirectories(destDir, dirsToPaste, isCut);

    QClipboard *clipboard = QApplication::clipboard();
    clipboard->clear();
}
コード例 #2
0
bool MessageEditor::qt_emit( int _id, QUObject* _o )
{
    switch ( _id - staticMetaObject()->signalOffset() ) {
    case 0: translationChanged((const QString&)static_QUType_QString.get(_o+1)); break;
    case 1: finished((bool)static_QUType_bool.get(_o+1)); break;
    case 2: prevUnfinished(); break;
    case 3: nextUnfinished(); break;
    case 4: updateActions((bool)static_QUType_bool.get(_o+1)); break;
    case 5: undoAvailable((bool)static_QUType_bool.get(_o+1)); break;
    case 6: redoAvailable((bool)static_QUType_bool.get(_o+1)); break;
    case 7: cutAvailable((bool)static_QUType_bool.get(_o+1)); break;
    case 8: copyAvailable((bool)static_QUType_bool.get(_o+1)); break;
    case 9: pasteAvailable((bool)static_QUType_bool.get(_o+1)); break;
    case 10: focusSourceList(); break;
    case 11: focusPhraseList(); break;
    default:
	return QWidget::qt_emit(_id,_o);
    }
    return TRUE;
}
コード例 #3
0
ファイル: editor.cpp プロジェクト: dgu123/qshaderedit
void Editor::onCurrentChanged(int idx)
{
    if(idx < 0) return;

    emit cursorPositionChanged();

    QTextDocument * document = currentTextEdit()->document();
    QTextCursor cursor = currentTextEdit()->textCursor();

    // update cursor position.
    emit cursorPositionChanged();

    // update copy/undo/redo available.
    emit copyAvailable(cursor.position() != cursor.anchor());
    emit undoAvailable(document->isUndoAvailable());
    emit redoAvailable(document->isRedoAvailable());
    emit pasteAvailable(true);

    connect(currentTextEdit(), SIGNAL(copyAvailable(bool)), this, SLOT(onCopyAvailable(bool)));
    connect(currentTextEdit(), SIGNAL(undoAvailable(bool)), this, SLOT(onUndoAvailable(bool)));
    connect(currentTextEdit(), SIGNAL(redoAvailable(bool)), this, SLOT(onRedoAvailable(bool)));
}
コード例 #4
0
ファイル: mainwindow.cpp プロジェクト: WatsonBauer/LimiEditor
void MainWindow::keyPressEvent( QKeyEvent *event )
{
    QMainWindow::keyPressEvent( event );
    emit pasteAvailable( ui->textEdit->canPaste() );
}
コード例 #5
0
void ConsoleWidget::copy()
{
  QTextEdit::copy();
  emit pasteAvailable(canPaste());
}
コード例 #6
0
void ConsoleWidget::focusInEvent(QFocusEvent * event)
{
  QTextEdit::focusInEvent(event);
  emit pasteAvailable(canPaste());
}
コード例 #7
0
void ConsoleWidget::keyPressEvent(QKeyEvent* event)
{
  switch(event->key())
  {
  case Qt::Key_Tab:
  case Qt::Key_Backtab:
    event->accept();
    {
      QTextCursor cursor = textCursor();
      int begin = cursor.position();
      int end = cursor.anchor();
      if(end < begin)
      {
        int tmp = end;
        end = begin;
        begin = tmp;
      }
      cursor.setPosition(end);
      cursor.movePosition(QTextCursor::StartOfLine, QTextCursor::KeepAnchor);
      QString line = cursor.selectedText();
      std::string command(line.toAscii().constData());
      std::string inputCommand = command;
      console.completeConsoleCommand(command, event->key() == Qt::Key_Tab, begin == end);
      if(command == inputCommand)
        QApplication::beep();
      else
      {
        QString newLine = command.c_str();
        int newBegin = cursor.position();
        int newEnd = newBegin + newLine.length();
        cursor.insertText(newLine);
        /*
        int i = 0;
        for(int len = std::min(line.length(), newLine.length()); i < len && line.at(i) == newLine.at(i); ++i);
        newBegin += i;
        */

        for(int i = command.length() - 2; i >= 0; --i)
        {
          char c = command[i];
          if(c == ' ' || c == ':' || c == '.')
          {
            newBegin += i + 1;
            break;
          }
        }

        cursor.setPosition(newBegin);
        cursor.setPosition(newEnd, QTextCursor::KeepAnchor);

        setTextCursor(cursor);
      }
    }
    break;

  case Qt::Key_Return:
  case Qt::Key_Enter:
    if(event->modifiers() & (Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier))
    {
      QTextCursor cursor = textCursor();
      cursor.insertBlock();
      setTextCursor(cursor);
    }
    else
    {
      event->accept();
      {
        QTextCursor cursor = textCursor();
        cursor.movePosition(QTextCursor::StartOfBlock);
        cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
        QString line = cursor.selectedText();
        cursor.movePosition(QTextCursor::EndOfLine);
        if(cursor.atEnd())
          cursor.insertText("\n");
        cursor.movePosition(QTextCursor::NextBlock);
        setTextCursor(cursor);

        // save output for the case that the simulator crashes
        if(consoleView.loadAndSaveOutput)
        {
          QSettings& settings = RoboCupCtrl::application->getLayoutSettings();
          settings.beginGroup(consoleView.fullName);
          settings.setValue("Output", toPlainText());
          settings.endGroup();
          output.clear();
        }

        // execute the command
        console.executeConsoleCommand(line.toAscii().constData());

        // stores unix like history entry
        history.removeAll(line);
        history.append(line);
        history_iter = history.end();
      }
    }
    break;

  case Qt::Key_Right:
    { // avoid jumping to the next line when the right arrow key is used to accept suggestions from tab completion
      bool handled = false;
      if(event->modifiers() == 0)
      {
        QTextCursor cursor = textCursor();
        int position = cursor.position();
        if(position > cursor.anchor())
        {
          cursor.movePosition(QTextCursor::EndOfBlock);
          if(cursor.position() == position)
          {
            handled = true;
            setTextCursor(cursor);
          }
        }
      }
      if(!handled)
        QTextEdit::keyPressEvent(event);
    }
    break;

    // History browsing keys
  case Qt::Key_Up:
    if((event->modifiers() & Qt::ControlModifier)
       && !history.isEmpty() && history_iter != history.begin())
    {
      event->accept();
      history_iter--;
      QTextCursor cursor = textCursor();
      cursor.movePosition(QTextCursor::End);
      cursor.movePosition(QTextCursor::StartOfBlock, QTextCursor::KeepAnchor);
      cursor.removeSelectedText();
      cursor.insertText(*history_iter);
      setTextCursor(cursor);
    }
    else
    {
      QTextEdit::keyPressEvent(event);
    }
    break;
  case Qt::Key_Down:
    if(event->modifiers() & Qt::ControlModifier)
    {
      event->accept();
      QTextCursor cursor = textCursor();
      cursor.movePosition(QTextCursor::End);
      cursor.movePosition(QTextCursor::StartOfBlock, QTextCursor::KeepAnchor);
      cursor.removeSelectedText();
      if(!history.isEmpty() && history_iter != history.end())
      {
        history_iter++;
        if(history_iter != history.end())
        {
          cursor.insertText(*history_iter);
          setTextCursor(cursor);
        }
      }
    }
    else
    {
      QTextEdit::keyPressEvent(event);
    }
    break;

  default:
    QTextEdit::keyPressEvent(event);
    if(event->matches(QKeySequence::Copy) || event->matches(QKeySequence::Cut))
      emit pasteAvailable(canPaste());
    break;
  }
}
コード例 #8
0
ファイル: pEditor.cpp プロジェクト: pasnox/monkeystudio2
void pEditor::clipboardDataChanged()
{
    mPasteAvailable = !QApplication::clipboard()->text().isEmpty();
    emit pasteAvailable( canPaste() );
}
コード例 #9
0
ファイル: sourceviewer.cpp プロジェクト: DmitriK/qupzilla
SourceViewer::SourceViewer(QWebEngineFrame* frame, const QString &selectedHtml)
    : QWidget(0)
    , m_frame(frame)
    , m_selectedHtml(selectedHtml)
{
    setAttribute(Qt::WA_DeleteOnClose);
    setWindowTitle(tr("Source of ") + QzTools::frameUrl(frame).toString());
    m_layout = new QBoxLayout(QBoxLayout::TopToBottom, this);
    m_sourceEdit = new PlainEditWithLines(this);
    m_sourceEdit->setObjectName("sourceviewer-textedit");
    m_sourceEdit->setReadOnly(true);
    m_sourceEdit->setUndoRedoEnabled(false);

    m_statusBar = new QStatusBar(this);
    m_statusBar->showMessage(QzTools::frameUrl(frame).toString());

    QMenuBar* menuBar = new QMenuBar(this);
    m_layout->addWidget(m_sourceEdit);
    m_layout->addWidget(m_statusBar);
    m_layout->setContentsMargins(0, 0, 0, 0);
    m_layout->setSpacing(0);
    m_layout->setMenuBar(menuBar);

    QFont font;
    font.setFamily("Tahoma");
    font.setFixedPitch(true);
    font.setPointSize(10);

    m_sourceEdit->setFont(font);
    new HtmlHighlighter(m_sourceEdit->document());

    resize(650, 600);
    QzTools::centerWidgetToParent(this, frame->page()->view());

    QMenu* menuFile = new QMenu(tr("File"));
    menuFile->addAction(tr("Load in page"), this, SLOT(loadInPage()));
    menuFile->addAction(QIcon::fromTheme("document-save"), tr("Save as..."), this, SLOT(save()))->setShortcut(QKeySequence("Ctrl+S"));
    menuFile->addSeparator();
    menuFile->addAction(QIcon::fromTheme("window-close"), tr("Close"), this, SLOT(close()))->setShortcut(QKeySequence("Ctrl+W"));
    menuBar->addMenu(menuFile);

    QMenu* menuEdit = new QMenu(tr("Edit"));
    m_actionUndo = menuEdit->addAction(QIcon::fromTheme("edit-undo"), tr("Undo"), m_sourceEdit, SLOT(undo()));
    m_actionRedo = menuEdit->addAction(QIcon::fromTheme("edit-redo"), tr("Redo"), m_sourceEdit, SLOT(redo()));
    menuEdit->addSeparator();
    m_actionCut = menuEdit->addAction(QIcon::fromTheme("edit-cut"), tr("Cut"), m_sourceEdit, SLOT(cut()));
    m_actionCopy = menuEdit->addAction(QIcon::fromTheme("edit-copy"), tr("Copy"), m_sourceEdit, SLOT(copy()));
    m_actionPaste = menuEdit->addAction(QIcon::fromTheme("edit-paste"), tr("Paste"), m_sourceEdit, SLOT(paste()));
    menuEdit->addSeparator();
    menuEdit->addAction(QIcon::fromTheme("edit-select-all"), tr("Select All"), m_sourceEdit, SLOT(selectAll()))->setShortcut(QKeySequence("Ctrl+A"));
    menuEdit->addAction(QIcon::fromTheme("edit-find"), tr("Find"), this, SLOT(findText()))->setShortcut(QKeySequence("Ctrl+F"));
    menuEdit->addSeparator();
    menuEdit->addAction(QIcon::fromTheme("go-jump"), tr("Go to Line..."), this, SLOT(goToLine()))->setShortcut(QKeySequence("Ctrl+L"));
    menuBar->addMenu(menuEdit);

    m_actionUndo->setShortcut(QKeySequence("Ctrl+Z"));
    m_actionRedo->setShortcut(QKeySequence("Ctrl+Shift+Z"));
    m_actionCut->setShortcut(QKeySequence("Ctrl+X"));
    m_actionCopy->setShortcut(QKeySequence("Ctrl+C"));
    m_actionPaste->setShortcut(QKeySequence("Ctrl+V"));

    QMenu* menuView = new QMenu(tr("View"));
    menuView->addAction(QIcon::fromTheme(QSL("view-refresh")), tr("Reload"), this, SLOT(reload()))->setShortcut(QKeySequence("F5"));
    menuView->addSeparator();
    menuView->addAction(tr("Editable"), this, SLOT(setTextEditable()))->setCheckable(true);
    menuView->addAction(tr("Word Wrap"), this, SLOT(setTextWordWrap()))->setCheckable(true);
    menuView->actions().at(3)->setChecked(true);
    menuBar->addMenu(menuView);

    connect(m_sourceEdit, SIGNAL(copyAvailable(bool)), this, SLOT(copyAvailable(bool)));
    connect(m_sourceEdit, SIGNAL(redoAvailable(bool)), this, SLOT(redoAvailable(bool)));
    connect(m_sourceEdit, SIGNAL(undoAvailable(bool)), this, SLOT(undoAvailable(bool)));
    connect(menuEdit, SIGNAL(aboutToShow()), this, SLOT(pasteAvailable()));

    QTimer::singleShot(0, this, SLOT(loadSource()));
}
コード例 #10
0
//-----------------------------------------------------------------------------------------
GenericTextEditor::GenericTextEditor(QString editorName, QWidget *parent) : QMdiArea(parent)
{
    mParentTabWidget = static_cast<QTabWidget*>(parent->parent());
    setObjectName(editorName);
    setViewMode(QMdiArea::TabbedView);

    QTabBar* tabBar = findChildren<QTabBar*>().at(0);
    tabBar->setTabsClosable(true);

    connect(tabBar, SIGNAL(tabCloseRequested(int)), this, SLOT(closeTab(int)));
    connect(tabBar, SIGNAL(currentChanged(int)),    this, SLOT(tabChanged(int)));
    connect(this,   SIGNAL(currentChanged(int)),    this, SLOT(tabChanged(int)));

    mActSave = new QAction(tr("Save"), this);
    mActSave->setStatusTip(tr("Save"));
    mActSave->setIcon( QIcon( ":/icons/filesave.svg" ));
    mActSave->setEnabled(false);
    
    mActEditCopy = new QAction(tr("Copy"), this);
    mActEditCopy->setStatusTip(tr("Copy Selected"));
    mActEditCopy->setIcon( QIcon( ":/icons/editcopy.svg"));
    mActEditCopy->setEnabled(false);

    mActEditCut = new QAction(tr("Cut"), this);
    mActEditCut->setStatusTip(tr("Cut Selected"));
    mActEditCut->setIcon( QIcon( ":/icons/editcut.svg"));
    mActEditCut->setEnabled(false);

    mActEditPaste = new QAction(tr("Paste"), this);
    mActEditPaste->setStatusTip(tr("Paste From Clipboard"));
    mActEditPaste->setIcon( QIcon( ":/icons/editpaste.svg"));
    mActEditPaste->setEnabled(false);


    mMainToolBar = new QToolBar();
    mMainToolBar->setObjectName("renderwindowtoolbar");
    mMainToolBar->setIconSize(QSize(20,20));
    mMainToolBar->setToolButtonStyle(Qt::ToolButtonIconOnly);
    mMainToolBar->addAction(mActSave);
    mMainToolBar->addSeparator();
    mMainToolBar->addAction(mActEditCut);
    mMainToolBar->addAction(mActEditCopy);
    mMainToolBar->addAction(mActEditPaste);

    QMainWindow *mw = static_cast<QMainWindow*>(this->parentWidget());
    mw->addToolBar(Qt::TopToolBarArea, mMainToolBar);

    mLastDocument = 0;

    connect(mActEditCut, SIGNAL(triggered()), this, SLOT(pasteAvailable()));
    connect(mActEditCopy, SIGNAL(triggered()), this, SLOT(pasteAvailable()));
    connect(mActSave, SIGNAL(triggered()), this, SLOT(onSave()));


    // Register the standard generic text editor codec extensions
    GenericTextEditorCodecFactory* genCodecFactory = new GenericTextEditorCodecFactory();
    GenericTextEditor::registerCodecFactory("txt",         genCodecFactory);
    GenericTextEditor::registerCodecFactory("xml",         genCodecFactory);
    GenericTextEditor::registerCodecFactory("ogscene",     genCodecFactory);
    GenericTextEditor::registerCodecFactory("html",        genCodecFactory);
    GenericTextEditor::registerCodecFactory("htm",         genCodecFactory);
    GenericTextEditor::registerCodecFactory("scene",       genCodecFactory);
    GenericTextEditor::registerCodecFactory("cfg",         genCodecFactory);
    GenericTextEditor::registerCodecFactory("log",         genCodecFactory);

    Ogitors::EventManager::getSingletonPtr()->connectEvent(Ogitors::EventManager::MODIFIED_STATE_CHANGE, this, true, 0, true, 0, EVENT_CALLBACK(GenericTextEditor, onModifiedStateChanged));
    Ogitors::EventManager::getSingletonPtr()->connectEvent(Ogitors::EventManager::LOAD_STATE_CHANGE, this, true, 0, true, 0, EVENT_CALLBACK(GenericTextEditor, onLoadStateChanged));
}
コード例 #11
0
ファイル: vdirectorytree.cpp プロジェクト: vscanf/vnote
void VDirectoryTree::contextMenuRequested(QPoint pos)
{
    QTreeWidgetItem *item = itemAt(pos);

    if (!m_notebook) {
        return;
    }

    QMenu menu(this);
    menu.setToolTipsVisible(true);

    if (!item) {
        // Context menu on the free space of the QTreeWidget
        menu.addAction(newRootDirAct);

        if (topLevelItemCount() > 1) {
            menu.addAction(m_sortAct);
        }
    } else {
        // Context menu on a QTreeWidgetItem
        menu.addAction(m_newNoteAct);

        if (item->parent()) {
            // Low-level item
            menu.addAction(newSubDirAct);

            if (item->parent()->childCount() > 1) {
                menu.addAction(m_sortAct);
            }
        } else {
            // Top-level item
            menu.addAction(newRootDirAct);
            menu.addAction(newSubDirAct);

            if (topLevelItemCount() > 1) {
                menu.addAction(m_sortAct);
            }
        }

        menu.addSeparator();
        menu.addAction(deleteDirAct);
        menu.addAction(copyAct);
        menu.addAction(cutAct);
    }

    if (pasteAvailable()) {
        if (!item) {
            menu.addSeparator();
        }

        menu.addAction(pasteAct);
    }

    menu.addSeparator();
    menu.addAction(m_reloadAct);

    if (item) {
        menu.addAction(m_openLocationAct);
        menu.addAction(dirInfoAct);
    }

    menu.exec(mapToGlobal(pos));
}