예제 #1
0
void EditStaff::updateInstrument()
      {
      setInterval(instrument.transpose());

      QList<StaffNameDoc>& nl = instrument.shortNames();
      QTextDocumentFragment df = nl.isEmpty() ? QTextDocumentFragment() : nl[0].name;
      shortName->setHtml(df.toHtml());

      nl = instrument.longNames();
      df = nl.isEmpty() ? QTextDocumentFragment() : nl[0].name;
      longName->setHtml(df.toHtml());

      if (partName->text() == instrumentName->text())    // Updates part name is no custom name has been set before
            partName->setText(instrument.trackName());

      instrumentName->setText(instrument.trackName());

      _minPitchA = instrument.minPitchA();
      _maxPitchA = instrument.maxPitchA();
      _minPitchP = instrument.minPitchP();
      _maxPitchP = instrument.maxPitchP();
      minPitchA->setText(midiCodeToStr(_minPitchA));
      maxPitchA->setText(midiCodeToStr(_maxPitchA));
      minPitchP->setText(midiCodeToStr(_minPitchP));
      maxPitchP->setText(midiCodeToStr(_maxPitchP));

      int numStr = instrument.stringData() ? instrument.stringData()->strings() : 0;
      numOfStrings->setText(QString::number(numStr));
      }
예제 #2
0
void TestChangeTrackedDelete::testPrefixMerge()
{
    TextTool *textTool = new TextTool(new MockCanvas);
    KoTextEditor *textEditor = textTool->textEditor();
    QVERIFY(textEditor);
    QTextDocument *document = textEditor->document();
    KTextDocumentLayout *layout = qobject_cast<KTextDocumentLayout*>(document->documentLayout());
    QTextCursor *cursor = textEditor->cursor();
    cursor->insertText("Hello World");
    cursor->setPosition(3);
    ChangeTrackedDeleteCommand *delCommand = new ChangeTrackedDeleteCommand(ChangeTrackedDeleteCommand::NextChar, textTool);
    textEditor->addCommand(delCommand);
    QCOMPARE(document->characterAt(3).unicode(), (ushort)(QChar::ObjectReplacementCharacter));
    cursor->setPosition(4);
    delCommand = new ChangeTrackedDeleteCommand(ChangeTrackedDeleteCommand::NextChar, textTool);
    textEditor->addCommand(delCommand);
    // This is wierd. Without this loop present the succeeding call to inlineTextObject returs NULL. Why ??????
    for (int i=0; i<document->characterCount(); i++) {
        cursor->setPosition(i);
    }
    cursor->setPosition(4);
    KDeleteChangeMarker *testMarker = dynamic_cast<KDeleteChangeMarker*>(layout->inlineTextObjectManager()->inlineTextObject(*cursor));
    QTextDocumentFragment deleteData =  KTextDocument(document).changeTracker()->elementById(testMarker->changeId())->deleteData();
    QCOMPARE(deleteData.toPlainText(), QString("lo"));
    delete textTool;
}
예제 #3
0
QMimeData* QTextBrowserEx::createMimeDataFromSelection() const
{
	QMimeData *data = new QMimeData();

	QTextCursor txtCursor = textCursor();
	QTextDocumentFragment htmlFrag = txtCursor.selection();

	data->setHtml(htmlFrag.toHtml());
	data->setText(htmlFrag.toPlainText());

	QString html = htmlFrag.toHtml();

	QList<QPair<QString,QTextCharFormat>> frags;
	getSelectTextFragments(frags);
	QList<QByteArray> lstFrags;
	for(int i = 0; i < frags.count(); i++)
	{
		const QPair<QString,QTextCharFormat> &frag = frags.at(i);
		QString txt = frag.first;
		QTextCharFormat txtfmt = frag.second;
		QByteArray buf;
		QDataStream ds(&buf, QIODevice::WriteOnly);
		ds << txt << txtfmt;
		lstFrags.push_back(buf);
	}
	QByteArray fragsBuffer;
	QDataStream dataStream(&fragsBuffer, QIODevice::WriteOnly);
	dataStream << lstFrags;
	data->setData(KTextEditMime, fragsBuffer);
 	return data;
}
/*! Copy text without images, but textual representations of the smileys. */
void InputTextWidget::copyPlainText()
{
    QTextDocumentFragment selection = textCursor().selection();
    if (!selection.isEmpty()) {
        QClipboard *clipboard = QApplication::clipboard();
        clipboard->setText(Smileypack::desmilify(selection.toHtml()));
    }
}
/*! Cut text without images, but textual representations of the smileys. */
void InputTextWidget::cutPlainText()
{
    QTextDocumentFragment selection = textCursor().selection();
    if(!selection.isEmpty()) {
        QClipboard *clipboard = QApplication::clipboard();
        clipboard->setText(EmoticonMenu::desmile(selection.toHtml()));
        textCursor().removeSelectedText();
    }
}
static PyObject *meth_QTextDocumentFragment_isEmpty(PyObject *sipSelf, PyObject *sipArgs)
{
    PyObject *sipParseErr = NULL;

    {
        QTextDocumentFragment *sipCpp;

        if (sipParseArgs(&sipParseErr, sipArgs, "B", &sipSelf, sipType_QTextDocumentFragment, &sipCpp))
        {
            bool sipRes;

            Py_BEGIN_ALLOW_THREADS
            sipRes = sipCpp->isEmpty();
            Py_END_ALLOW_THREADS

            return PyBool_FromLong(sipRes);
        }
    }
예제 #7
0
void EditWidget::insertTextFragment(const QTextDocumentFragment &AFragment)
{
	if (!AFragment.isEmpty())
	{
		if (isRichTextEnabled())
			ui.medEditor->textCursor().insertFragment(prepareTextFragment(AFragment));
		else
			ui.medEditor->textCursor().insertText(prepareTextFragment(AFragment).toPlainText());
	}
}
예제 #8
0
QTextDocumentFragment EditWidget::prepareTextFragment(const QTextDocumentFragment &AFragment)
{
	QTextDocumentFragment fragment;
	if (!AFragment.isEmpty())
	{
		QMimeData data;
		data.setHtml(AFragment.toHtml());

		QTextDocument doc;
		QMap<int,IMessageEditContentsHandler *> handlers = FMessageWidgets->editContentsHandlers();
		for (QMap<int,IMessageEditContentsHandler *>::const_iterator it = handlers.constBegin(); it!=handlers.constEnd(); ++it)
			if (it.value()->messageEditContentsInsert(it.key(),this,&data,&doc))
				break;

		if (isRichTextEnabled())
			fragment = QTextDocumentFragment::fromHtml(doc.toHtml());
		else
			fragment = QTextDocumentFragment::fromPlainText(doc.toPlainText());
	}
	return fragment;
}
예제 #9
0
int KoChangeTracker::getDeleteChangeId(QString title, QTextDocumentFragment selection, int existingChangeId)
{
    if ( existingChangeId ) {
        d->m_childs.insert(existingChangeId, d->m_changeId);
        d->m_parents.insert(d->m_changeId, existingChangeId);
    }

    KoChangeTrackerElement *changeElement = new KoChangeTrackerElement(title, KoGenChange::deleteChange);

    changeElement->setDate(KDateTime::currentLocalDateTime().toString(KDateTime::ISODate));
    changeElement->setCreator(QString("essai delete"));
    //TODO preserve formating info there. this will do for now
    changeElement->setDeleteData(selection.toPlainText());

    changeElement->setEnabled(d->m_enabled);

    d->m_changes.insert(d->m_changeId, changeElement);

    return d->m_changeId++;
}
예제 #10
0
파일: text.cpp 프로젝트: aeliot/MuseScore
void Text::setText(const QTextDocumentFragment& f)
      {
      setHtml(f.toHtml());
      }
예제 #11
0
bool ChatTextEdit::eventFilter(QObject *obj, QEvent *event)
{
    if (event->type() == QEvent::KeyPress)
    {
        QKeyEvent *keyEvent = (QKeyEvent *) event;

        if (keyEvent->key() == Qt::Key_Up)
        {
            // Key up
            QTextCursor cursor = textCursor();
            int pos = cursor.position();
            bool sel = keyEvent->modifiers() == Qt::ShiftModifier;
            cursor.movePosition(QTextCursor::Up, (sel ? QTextCursor::KeepAnchor : QTextCursor::MoveAnchor));

            if (pos == cursor.position())
                cursor.movePosition(QTextCursor::Start, (sel ? QTextCursor::KeepAnchor : QTextCursor::MoveAnchor));

            setTextCursor(cursor);

            return true;
        }
        else  if (keyEvent->key() == Qt::Key_Down)
        {
            // Key down
            QTextCursor cursor = textCursor();
            int pos = cursor.position();
            bool sel = keyEvent->modifiers() == Qt::ShiftModifier;
            cursor.movePosition(QTextCursor::Down, (sel ? QTextCursor::KeepAnchor : QTextCursor::MoveAnchor));

            if (pos == cursor.position())
                cursor.movePosition(QTextCursor::End, (sel ? QTextCursor::KeepAnchor : QTextCursor::MoveAnchor));

            setTextCursor(cursor);
            return true;
        }
        else if (keyEvent->nativeScanCode() == 36)
        {
            // Return pressed
            if (Client::enterIsSend && !(keyEvent->modifiers() & Qt::ShiftModifier))
            {
                isComposing = false;
                emit returnPressed();
                return true;
            }
        }
        else if (keyEvent->nativeScanCode() == 54 &&
                 keyEvent->modifiers() == Qt::ControlModifier)
        {
            // Copy
            QTextCursor cursor = textCursor();
            if (cursor.hasSelection())
            {
                QTextDocumentFragment selection = cursor.selection();
                QClipboard *clipboard = QApplication::clipboard();
                clipboard->setText(Utilities::htmlToWAText(selection.toHtml()));

                QMaemo5InformationBox::information(this,"Copied");
                return true;
            }
        }
        else if (keyEvent->nativeScanCode() == 55 &&
                 keyEvent->modifiers() == Qt::ControlModifier)
        {
            // Paste event
            QTextCursor cursor = textCursor();
            QClipboard *clipboard = QApplication::clipboard();

            cursor.insertHtml(Utilities::WATextToHtml(clipboard->text(),32,false));

            return true;
        }
        else if (!isComposing)
        {
            isComposing = true;
            emit composing();
        }
        else
        {
            lastKeyPressed = QDateTime::currentMSecsSinceEpoch();
            composingTimer.start(2000);
        }
    }
    else if (event->type() == QEvent::InputMethod)
    {
        QInputMethodEvent *inputEvent = (QInputMethodEvent *) event;

        //Utilities::logData("Commit String: '" + inputEvent->commitString() + "'");
        if (inputEvent->commitString() == "\n" && Client::enterIsSend)
        {
            // Let's hide the keyboard if it was shown
            QTimer::singleShot(0,this,SLOT(closeKB()));
            isComposing = false;
            emit returnPressed();
            return true;
        }
    }

    return QTextEdit::eventFilter(obj,event);
}
예제 #12
0
int main(int argc, char *argv[]){

     // here the QT_program is created
     QApplication app(argc, argv);

     //Qt translations
     QTranslator qtTranslator;
     qtTranslator.load("qt_" + QLocale::system().name(),
       QLibraryInfo::location(QLibraryInfo::TranslationsPath));
     app.installTranslator(&qtTranslator);

     //My translations
     QTranslator translator;
     QString trDir = "/usr/share/qshutdown/translations/";
     translator.load(trDir + "qshutdown-" + QLocale::system().name());
     app.installTranslator(&translator);

     QTextStream myOutput(stdout);

     if(!QProcessEnvironment().isEmpty())
       shell = QProcess::systemEnvironment().filter("SHELL").first().remove("SHELL=");
     if(shell.isEmpty() && QFile("/bin/bash").exists())
       shell = "/bin/bash";
     else
       myOutput << "E: No shell found! Custom commands won't work!";

     QString infoStr = QString(QObject::tr("qshutdown will show itself 3 times as a warning "
       "if there are less than 70 seconds left.<br/><br/>This program uses qdbus to send a "
       "shutdown/reboot/suspend/hibernate request to either the gnome- or "
       "kde-session-manager, to HAL/ConsoleKit/DeviceKit/UPower and if none of these works, the "
       "command 'sudo shutdown' will be used (note that when sending the shutdown request to HAL or "
       "ConsoleKit, or the shutdown command is used, the Session will never be saved. If the "
       "shutdown command is used, the program will only be able to shutdown and reboot). So "
       "if nothing happens when the shutdown- or reboot-time is reached, it means that one "
       "lacks the rights for the shutdown command. In this case one can do the following:"
       "<br/><br/>Paste the following in a terminal:<pre>EDITOR=nano sudo -E visudo</pre>and "
       "add this line:<pre>* ALL = NOPASSWD:/sbin/shutdown</pre>whereas * replaces the "
       "user name or %group name.<br/><br/>The maximum Number of countdown_minutes is "
       "1440 (24 hours).<br/>The configuration file (and logfile) is located at "
       "<i>~/.qshutdown/</i> (under Linux/Unix).<br/><br/><b>For admins:</b><br/>If you want "
       "qshutdown to run with \"parental lock\" for every user, you can do "
       "\"sudo cp /usr/share/qshutdown/autostart/99qshutdown /etc/X11/Xsession.d/\" "
       "and set the option Lock_all in /root/.qshutdown/qshutdown.conf to true. Note that "
       "qshutdown has to start once to generate the qshutdown.conf. Furthermore there is a "
       "need to add the following line to the sudoers (as above):"
       "<pre>* ALL = NOPASSWD:/usr/bin/qshutdown</pre><br/>If you should ever forget "
       "your set password, just remove the whole line starting with \"Password\" manually from "
       "the qshutdown.conf.<br/><br/><b>Hints on usage:</b><br/>If you want qshutdown to stop "
       "\"bugging\" you, just remove the hook from "
       "\"warnings on?\".<br/><br/><b>Hotkeys:</b><table border=\"1\"><tr><td>Ctrl+I</td><td>(this)"
       " information window</td></tr><tr><td>Ctrl+Q</td><td>Quit</td></tr><tr><td>Ctrl+P</td>"
       "<td>Preferences</td></tr><tr><td>Ctrl+L</td><td>write the run time once into the logfile (works "
       "only if qshutdown quits. To make it permanent set it in the preferences.)</td></tr><tr>"
       "<td>Ctrl+S</td><td>set to shutdown</td></tr><tr><td>Ctrl+R</td><td>set to restart</td></tr>"
       "<tr><td>Ctrl+U</td><td>set to suspend to RAM</td></tr><tr><td>Ctrl+H</td><td>set to hibernate"
       "</td></tr><tr><td>Ctrl+E</td><td>stop countdown (only if the countdown has started and the admin "
       "didn't restrict the access)</td></tr><tr><td>Shift+E</td><td>to edit the configuration file (for "
       "this a password is necessary. If you are a user, you can set an \"empty password\" (leave the "
       "password field empty)).</td></tr></table>"));
     QTextDocumentFragment infoDoc;
     infoDoc = QTextDocumentFragment::fromHtml(infoStr);
     QString info = infoDoc.toPlainText();

     //Get the arguments passed from the terminal
     QStringList args = QApplication::arguments();
     args.removeFirst(); //this is just the program
     for(int i=1; i<args.size();args.removeLast());
     if(!args.empty()){
       QString arg = args[0];
       if(arg[0] == '-'){
         if(arg[1] == 'h' || arg == "--help")
           myOutput << "\nqshutdown [ options ... ]\n\nOptions are:\n\t-h "
                    << "or --help\tPrints this message.\n\t-i\t\tPrints "
                    << "information.\n\t-v\t\tPrints all errors and warnings.\n"
                    << "\t-s or --start\tStarts the countdown for the set time."
                    << endl;
         if(arg[1] == 'i')
           myOutput << info << endl;
       }
       if(arg != "-h" && arg != "--help" && arg != "-i"
        && !((arg[0] == '-' && (arg.contains("s") || arg.contains("v")))
          || args.contains("--start")))
         myOutput << "Wrong options! Try qshutdown -h" << endl;
       if(arg.contains("-") && arg.contains("-v"))
         verbose = true;
     }

     if(!args.empty() && !((args[0][0] == '-' && (args[0].contains("v")
       || args[0].contains("s"))) || args.contains("--start")))
       exit(0);

     Gui window; //Create the main widget

     #ifndef Q_OS_WIN32
       QDBusConnection::sessionBus().registerObject(OBJECT_NAME, &window,
         QDBusConnection::ExportScriptableSlots);
       if(QDBusConnection::sessionBus().registerService(SERVICE_NAME)){
         //if possible register qshutdown as a service in the session bus
     #endif //Q_OS_WIN32
         window.information = infoStr;
         window.loadSettings();
         window.center();
         window.show();
         app.setQuitOnLastWindowClosed(false);
         if(!args.empty() && ((args[0][0] == '-' && args[0].contains("s"))
           || args.contains("--start")))
           window.set();

         return app.exec();

     #ifndef Q_OS_WIN32
       }
       else{ //if registering qshutdown fails (also because it is already
             // registered, show window
         myOutput << "\nqshutdown is already running!\n" << endl;
         QDBusInterface iface(SERVICE_NAME, OBJECT_NAME, "",
           QDBusConnection::sessionBus(), &window);
         QDBusMessage response = iface.call("showRunningProgram");
         if(response.type() == QDBusMessage::ErrorMessage){
           if(verbose)
             myOutput << "QDBusInterface " << iface.interface() << " seems to be valid... -> "
                      << (iface.isValid()? "true":"false") << "\nW: " << response.errorName()
                      << ": " << response.errorMessage() << "\nYou can ignore this.\n\n" << endl;
           QDBusInterface iface2(SERVICE_NAME, OBJECT_NAME, "local.Gui",
             QDBusConnection::sessionBus(), &window);
           QDBusMessage response2 = iface2.call("showRunningProgram");
           if(response2.type() == QDBusMessage::ErrorMessage)
             myOutput << "QDBusInterface " << iface2.interface() << " seems to be valid... -> "
                      << (iface2.isValid()? "true":"false") << "\nW: " << response2.errorName()
                      << ": " << response2.errorMessage() << "\nPlease report this." << endl;
           else if(!args.empty() && ((args[0][0] == '-' && args[0].contains("s"))
             || args.contains("--start")))
             iface2.call("set");
         }
         else if(!args.empty() && ((args[0][0] == '-' && args[0].contains("s"))
           || args.contains("--start")))
           iface.call("set");
       }
       if(!args.empty() && ((args[0][0] == '-' && args[0].contains("s"))
           || args.contains("--start")))
           myOutput << "Starting countdown!\n";
     #endif //Q_OS_WIN32
}