ExprEditor::ExprEditor(QWidget* parent,ExprControlCollection* controls) : QWidget(parent),_updatingText(0),errorHeight(0) { // timers controlRebuildTimer=new QTimer(); previewTimer=new QTimer(); // title and minimum size setWindowTitle("Expression Editor"); setMinimumHeight(100); // expression controls, we need for signal connections this->controls = controls; // make layout QVBoxLayout* exprAndErrors=new QVBoxLayout; exprAndErrors->setMargin(0); setLayout(exprAndErrors); // create text editor widget exprTe = new ExprTextEdit(this); exprTe->setMinimumHeight(50); // calibrate the font size int fontsize = 12; while (QFontMetrics(QFont("Liberation Sans",fontsize)).width("abcdef")<38 && fontsize<20) fontsize++; while (QFontMetrics(QFont("Liberation Sans",fontsize)).width("abcdef")>44 && fontsize>3) fontsize--; exprTe->setFont(QFont("Liberation Sans",fontsize)); exprAndErrors->addWidget(exprTe); // create error widget errorWidget=new QListWidget(); errorWidget->setSelectionMode(QAbstractItemView::SingleSelection); errorWidget->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::Maximum)); connect(errorWidget,SIGNAL(itemSelectionChanged()),SLOT(selectError())); clearErrors(); exprAndErrors->addWidget(errorWidget); // wire up signals connect(exprTe, SIGNAL(applyShortcut()), SLOT(sendApply())); connect(exprTe, SIGNAL(nextError()), SLOT(nextError())); connect(exprTe, SIGNAL(textChanged()), SLOT(exprChanged())); connect(controls,SIGNAL(controlChanged(int)),SLOT(controlChanged(int))); connect(controls,SIGNAL(insertString(const std::string&)),SLOT(insertStr(const std::string&))); connect(controlRebuildTimer, SIGNAL(timeout()), SLOT(rebuildControls())); connect(previewTimer, SIGNAL(timeout()), SLOT(sendPreview())); }
MakeViewPart::MakeViewPart(QObject *parent, const char *name, const QStringList &) : KDevMakeFrontend(&data, parent, name) { setInstance(MakeViewFactory::instance()); setXMLFile("kdevmakeview.rc"); m_dcop = new KDevMakeFrontendIface(this); m_widget = new MakeWidget(this); m_widget->setIcon( SmallIcon("exec") ); m_widget->setCaption(i18n("Messages Output")); QWhatsThis::add(m_widget, i18n("<b>Messages output</b><p>" "The messages window shows the output of the compiler and " "used build tools like make, ant, uic, dcopidl etc. " "For compiler error messages, click on the error message. " "This will automatically open the source file and set the " "cursor to the line that caused the compiler error/warning.")); mainWindow()->embedOutputView(m_widget, i18n("Messages"), i18n("Compiler output messages")); KAction *action; action = new KAction( i18n("&Next Error"), Key_F4, m_widget, SLOT(nextError()), actionCollection(), "view_next_error"); action->setToolTip( i18n("Go to the next error") ); action->setWhatsThis(i18n("<b>Next error</b><p>Switches to the file and line where the next error was reported from.")); action = new KAction( i18n("&Previous Error"), SHIFT+Key_F4, m_widget, SLOT(prevError()), actionCollection(), "view_previous_error"); action->setToolTip( i18n("Go to the previous error") ); action->setWhatsThis(i18n("<b>Previous error</b><p>Switches to the file and line where the previous error was reported from.")); connect( core(), SIGNAL(stopButtonClicked(KDevPlugin*)), this, SLOT(slotStopButtonClicked(KDevPlugin*)) ); }
void ExprTextEdit::keyPressEvent( QKeyEvent* e ) { // Accept expression if (e->key()==Qt::Key_Return && e->modifiers()==Qt::ControlModifier){ emit applyShortcut(); return ; }else if(e->key()==Qt::Key_F4){ emit nextError(); return; } // If the completer is active pass keys it needs down if(completer && completer->popup()->isVisible()){ switch(e->key()){ case Qt::Key_Enter:case Qt::Key_Return:case Qt::Key_Escape: case Qt::Key_Tab:case Qt::Key_Backtab: e->ignore();return; default: break; } } // use the values here as long as we are not using the shortcut to bring up the editor bool isShortcut = ((e->modifiers() & Qt::ControlModifier) && e->key() == Qt::Key_E); // CTRL+E if (!isShortcut) // dont process the shortcut when we have a completer QTextEdit::keyPressEvent(e); const bool ctrlOrShift = e->modifiers() & (Qt::ControlModifier | Qt::ShiftModifier); if (!completer || (ctrlOrShift && e->text().isEmpty())) return; bool hasModifier=(e->modifiers()!=Qt::NoModifier) && !ctrlOrShift; // grab the line we're on QTextCursor tc=textCursor(); tc.movePosition(QTextCursor::StartOfLine, QTextCursor::KeepAnchor); QString line=tc.selectedText(); // matches the last prefix of a completable variable or function and extract as completionPrefix static QRegExp completion("^(?:.*[^A-Za-z0-9_$])?((?:\\$[A-Za-z0-9_]*)|[A-Za-z]+[A-Za-z0-9_]*)$"); int index=completion.indexIn(line); QString completionPrefix; if(index != -1 && !line.contains('#')){ completionPrefix=completion.cap(1); //std::cout<<"we have completer prefix '"<<completionPrefix.toStdString()<<"'"<<std::endl; } // hide the completer if we have too few characters, we are at end of word if(!isShortcut && (hasModifier || e->text().isEmpty() || completionPrefix.length()<1 || index==-1)){ completer->popup()->hide(); }else if (_popupEnabledAction->isChecked()) { // copy the completion prefix in if we don't already have it in the completer if(completionPrefix!=completer->completionPrefix()){ completer->setCompletionPrefix(completionPrefix); completer->popup()->setCurrentIndex(completer->completionModel()->index(0,0)); } // display the completer QRect cr=cursorRect(); cr.setWidth(completer->popup()->sizeHintForColumn(0)+completer->popup()->sizeHintForColumn(1) + completer->popup()->verticalScrollBar()->sizeHint().width()); cr.translate(0,6); completer->complete(cr); hideTip(); return; } // documentation completion static QRegExp inFunction("^(?:.*[^A-Za-z0-9_$])?([A-Za-z0-9_]+)\\([^()]*$"); int index2=inFunction.indexIn(line); if(index2!=-1){ QString functionName=inFunction.cap(1); QStringList tips=completionModel->getDocString(functionName).split("\n"); QString tip="<b>"+tips[0]+"</b>"; for(int i=1;i<tips.size();i++){ tip+="<br>"+tips[i]; } if (_popupEnabledAction->isChecked()) showTip(tip); //QToolTip::showText(mapToGlobal(cr.bottomLeft()),tip,this,cr); }else{ hideTip(); } }
void toPLSQLEditor::createActions(void) { refreshAct = new QAction(QIcon(QPixmap(const_cast<const char**>(refresh_xpm))), tr("Refresh"), this); connect(refreshAct, SIGNAL(triggered()), this, SLOT(refresh()), Qt::QueuedConnection); refreshAct->setShortcut(QKeySequence::Refresh); describeAct = new QAction(QPixmap(const_cast<const char**>(describe_xpm)), tr("Describe under cursor"), this); describeAct->setShortcut(Qt::Key_F4); connect(describeAct, SIGNAL(triggered()), this, SLOT(describe(void))); newSheetAct = new QAction(QIcon(QPixmap(const_cast<const char**>(toworksheet_xpm))), tr("&New Sheet"), this); connect(newSheetAct, SIGNAL(triggered()), this, SLOT(newSheet()), Qt::QueuedConnection); compileAct = new QAction(QIcon(QPixmap(const_cast<const char**>(compile_xpm))), tr("&Compile"), this); connect(compileAct, SIGNAL(triggered()), this, SLOT(compile()), Qt::QueuedConnection); compileAct->setShortcut(Qt::Key_F9); compileWarnAct = new QAction(QIcon(QPixmap(const_cast<const char**>(compilewarning_xpm))), tr("&Compile with Warnings"), this); connect(compileWarnAct, SIGNAL(triggered()), this, SLOT(compileWarn()), Qt::QueuedConnection); closeAct = new QAction(QIcon(QPixmap(const_cast<const char**>(close_xpm))), tr("Close"), this); connect(closeAct, SIGNAL(triggered()), this, SLOT(closeEditor()), Qt::QueuedConnection); closeAllAct = new QAction(tr("Close All"), this); connect(closeAllAct, SIGNAL(triggered()), this, SLOT(closeAllEditor()), Qt::QueuedConnection); nextErrorAct = new QAction(QIcon(QPixmap(const_cast<const char**>(nextbug_xpm))), tr("Next &Error"), this); connect(nextErrorAct, SIGNAL(triggered()), this, SLOT(nextError()), Qt::QueuedConnection); nextErrorAct->setShortcut(Qt::CTRL + Qt::Key_N); previousErrorAct = new QAction(QIcon(QPixmap(const_cast<const char**>(prevbug_xpm))), tr("Pre&vious Error"), this); connect(previousErrorAct, SIGNAL(triggered()), this, SLOT(prevError()), Qt::QueuedConnection); previousErrorAct->setShortcut(Qt::CTRL + Qt::Key_P); // tool button to check code checkCodeAct = new QAction(QIcon(QPixmap(const_cast<const char**>(checkcode_xpm))), tr("&Check Code"), this); connect(checkCodeAct, SIGNAL(triggered()), this, SLOT(checkCode()), Qt::QueuedConnection); checkCodeAct->setShortcut(Qt::CTRL + Qt::Key_G); // TODO: change shortcut to something meaningful :) }