Exemple #1
0
void PathDeformControls::layoutForDesktop()
{
    QGroupBox* mainGroup = new QGroupBox(this);
    mainGroup->setTitle(tr("Controls"));

    QGroupBox *radiusGroup = new QGroupBox(mainGroup);
    radiusGroup->setTitle(tr("Lens Radius"));
    QSlider *radiusSlider = new QSlider(Qt::Horizontal, radiusGroup);
    radiusSlider->setRange(15, 150);
    radiusSlider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);

    QGroupBox *deformGroup = new QGroupBox(mainGroup);
    deformGroup->setTitle(tr("Deformation"));
    QSlider *deformSlider = new QSlider(Qt::Horizontal, deformGroup);
    deformSlider->setRange(-100, 100);
    deformSlider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);

    QGroupBox *fontSizeGroup = new QGroupBox(mainGroup);
    fontSizeGroup->setTitle(tr("Font Size"));
    QSlider *fontSizeSlider = new QSlider(Qt::Horizontal, fontSizeGroup);
    fontSizeSlider->setRange(16, 200);
    fontSizeSlider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);

    QGroupBox *textGroup = new QGroupBox(mainGroup);
    textGroup->setTitle(tr("Text"));
    QLineEdit *textInput = new QLineEdit(textGroup);

    QPushButton *animateButton = new QPushButton(mainGroup);
    animateButton->setText(tr("Animated"));
    animateButton->setCheckable(true);

    QPushButton *showSourceButton = new QPushButton(mainGroup);
    showSourceButton->setText(tr("Show Source"));

#ifdef QT_OPENGL_SUPPORT
    QPushButton *enableOpenGLButton = new QPushButton(mainGroup);
    enableOpenGLButton->setText(tr("Use OpenGL"));
    enableOpenGLButton->setCheckable(true);
    enableOpenGLButton->setChecked(m_renderer->usesOpenGL());
    if (!QGLFormat::hasOpenGL())
        enableOpenGLButton->hide();
#endif

    QPushButton *whatsThisButton = new QPushButton(mainGroup);
    whatsThisButton->setText(tr("What's This?"));
    whatsThisButton->setCheckable(true);


    mainGroup->setFixedWidth(180);

    QVBoxLayout *mainGroupLayout = new QVBoxLayout(mainGroup);
    mainGroupLayout->addWidget(radiusGroup);
    mainGroupLayout->addWidget(deformGroup);
    mainGroupLayout->addWidget(fontSizeGroup);
    mainGroupLayout->addWidget(textGroup);
    mainGroupLayout->addWidget(animateButton);
    mainGroupLayout->addStretch(1);
#ifdef QT_OPENGL_SUPPORT
    mainGroupLayout->addWidget(enableOpenGLButton);
#endif
    mainGroupLayout->addWidget(showSourceButton);
    mainGroupLayout->addWidget(whatsThisButton);

    QVBoxLayout *radiusGroupLayout = new QVBoxLayout(radiusGroup);
    radiusGroupLayout->addWidget(radiusSlider);

    QVBoxLayout *deformGroupLayout = new QVBoxLayout(deformGroup);
    deformGroupLayout->addWidget(deformSlider);

    QVBoxLayout *fontSizeGroupLayout = new QVBoxLayout(fontSizeGroup);
    fontSizeGroupLayout->addWidget(fontSizeSlider);

    QVBoxLayout *textGroupLayout = new QVBoxLayout(textGroup);
    textGroupLayout->addWidget(textInput);

    QVBoxLayout * mainLayout = new QVBoxLayout(this);
    mainLayout->addWidget(mainGroup);
    mainLayout->setMargin(0);

    connect(radiusSlider, SIGNAL(valueChanged(int)), m_renderer, SLOT(setRadius(int)));
    connect(deformSlider, SIGNAL(valueChanged(int)), m_renderer, SLOT(setIntensity(int)));
    connect(fontSizeSlider, SIGNAL(valueChanged(int)), m_renderer, SLOT(setFontSize(int)));
    connect(animateButton, SIGNAL(clicked(bool)), m_renderer, SLOT(setAnimated(bool)));
#ifdef QT_OPENGL_SUPPORT
    connect(enableOpenGLButton, SIGNAL(clicked(bool)), m_renderer, SLOT(enableOpenGL(bool)));
#endif

    connect(textInput, SIGNAL(textChanged(QString)), m_renderer, SLOT(setText(QString)));
    connect(m_renderer, SIGNAL(descriptionEnabledChanged(bool)),
            whatsThisButton, SLOT(setChecked(bool)));
    connect(whatsThisButton, SIGNAL(clicked(bool)), m_renderer, SLOT(setDescriptionEnabled(bool)));
    connect(showSourceButton, SIGNAL(clicked()), m_renderer, SLOT(showSource()));

    animateButton->animateClick();
    deformSlider->setValue(80);
    fontSizeSlider->setValue(120);
    radiusSlider->setValue(100);
    textInput->setText(tr("Qt"));
}
Exemple #2
0
    RaceDialog::RaceDialog()
      : WindowModal("openmw_chargen_race.layout")
      , mGenderIndex(0)
      , mFaceIndex(0)
      , mHairIndex(0)
      , mCurrentAngle(0)
      , mPreviewDirty(true)
    {
        // Centre dialog
        center();

        setText("AppearanceT", MWBase::Environment::get().getWindowManager()->getGameSettingString("sRaceMenu1", "Appearance"));
        getWidget(mPreviewImage, "PreviewImage");

        getWidget(mHeadRotate, "HeadRotate");

        mHeadRotate->setScrollRange(1000);
        mHeadRotate->setScrollPosition(500);
        mHeadRotate->setScrollViewPage(50);
        mHeadRotate->setScrollPage(50);
        mHeadRotate->setScrollWheelPage(50);
        mHeadRotate->eventScrollChangePosition += MyGUI::newDelegate(this, &RaceDialog::onHeadRotate);

        // Set up next/previous buttons
        MyGUI::Button *prevButton, *nextButton;

        setText("GenderChoiceT", MWBase::Environment::get().getWindowManager()->getGameSettingString("sRaceMenu2", "Change Sex"));
        getWidget(prevButton, "PrevGenderButton");
        getWidget(nextButton, "NextGenderButton");
        prevButton->eventMouseButtonClick += MyGUI::newDelegate(this, &RaceDialog::onSelectPreviousGender);
        nextButton->eventMouseButtonClick += MyGUI::newDelegate(this, &RaceDialog::onSelectNextGender);

        setText("FaceChoiceT", MWBase::Environment::get().getWindowManager()->getGameSettingString("sRaceMenu3", "Change Face"));
        getWidget(prevButton, "PrevFaceButton");
        getWidget(nextButton, "NextFaceButton");
        prevButton->eventMouseButtonClick += MyGUI::newDelegate(this, &RaceDialog::onSelectPreviousFace);
        nextButton->eventMouseButtonClick += MyGUI::newDelegate(this, &RaceDialog::onSelectNextFace);

        setText("HairChoiceT", MWBase::Environment::get().getWindowManager()->getGameSettingString("sRaceMenu4", "Change Hair"));
        getWidget(prevButton, "PrevHairButton");
        getWidget(nextButton, "NextHairButton");
        prevButton->eventMouseButtonClick += MyGUI::newDelegate(this, &RaceDialog::onSelectPreviousHair);
        nextButton->eventMouseButtonClick += MyGUI::newDelegate(this, &RaceDialog::onSelectNextHair);

        setText("RaceT", MWBase::Environment::get().getWindowManager()->getGameSettingString("sRaceMenu5", "Race"));
        getWidget(mRaceList, "RaceList");
        mRaceList->setScrollVisible(true);
        mRaceList->eventListSelectAccept += MyGUI::newDelegate(this, &RaceDialog::onAccept);
        mRaceList->eventListChangePosition += MyGUI::newDelegate(this, &RaceDialog::onSelectRace);

        setText("SkillsT", MWBase::Environment::get().getWindowManager()->getGameSettingString("sBonusSkillTitle", "Skill Bonus"));
        getWidget(mSkillList, "SkillList");
        setText("SpellPowerT", MWBase::Environment::get().getWindowManager()->getGameSettingString("sRaceMenu7", "Specials"));
        getWidget(mSpellPowerList, "SpellPowerList");

        MyGUI::Button* backButton;
        getWidget(backButton, "BackButton");
        backButton->eventMouseButtonClick += MyGUI::newDelegate(this, &RaceDialog::onBackClicked);

        MyGUI::Button* okButton;
        getWidget(okButton, "OKButton");
        okButton->setCaption(MWBase::Environment::get().getWindowManager()->getGameSettingString("sOK", ""));
        okButton->eventMouseButtonClick += MyGUI::newDelegate(this, &RaceDialog::onOkClicked);

        updateRaces();
        updateSkills();
        updateSpellPowers();
    }
void SFMLCursesTextBox::append(const std::string& text)
{
	setText(m_text.append(text));
}
void DoubleEditor::setValue(const double &d) { setText(formatValue(d)); }
Exemple #5
0
void LocationBar::keyPressEvent(QKeyEvent* event)
{
    switch (event->key()) {
    case Qt::Key_V:
        if (event->modifiers() == (Qt::ControlModifier | Qt::ShiftModifier)) {
            pasteAndGo();
            event->accept();
            return;
        }
        break;

    case Qt::Key_Down:
        m_completer->complete(text());
        break;

    case Qt::Key_Left:
        m_completer->closePopup();
        break;

    case Qt::Key_Escape:
        m_webView->setFocus();
        showUrl(m_webView->url());
        event->accept();
        break;

    case Qt::Key_Alt:
        m_holdingAlt = true;
        break;

    case Qt::Key_Return:
    case Qt::Key_Enter:
        switch (event->modifiers()) {
        case Qt::ControlModifier:
            if (!text().endsWith(QL1S(".com")))
                setText(text().append(QL1S(".com")));
            requestLoadUrl();
            m_holdingAlt = false;
            break;

        case Qt::AltModifier:
            m_completer->closePopup();
            m_window->tabWidget()->addView(createLoadRequest());
            m_holdingAlt = false;
            break;

        default:
            requestLoadUrl();
            m_holdingAlt = false;
        }

        break;

    case Qt::Key_0:
    case Qt::Key_1:
    case Qt::Key_2:
    case Qt::Key_3:
    case Qt::Key_4:
    case Qt::Key_5:
    case Qt::Key_6:
    case Qt::Key_7:
    case Qt::Key_8:
    case Qt::Key_9:
        if (event->modifiers() & Qt::AltModifier || event->modifiers() & Qt::ControlModifier) {
            event->ignore();
            m_holdingAlt = false;
            return;
        }
        break;

    default:
        m_holdingAlt = false;
    }

    LineEdit::keyPressEvent(event);
}
Exemple #6
0
SonicPiScintilla::SonicPiScintilla(SonicPiLexer *lexer, SonicPiTheme *theme)
  : QsciScintilla()
{
  this->theme = theme;
  standardCommands()->clearKeys();
  standardCommands()->clearAlternateKeys();
  QString skey;
  QSettings settings("sonic-pi.net", "Key bindings");

#if defined(Q_OS_MAC)
  int SPi_CTRL = Qt::META;
  int SPi_META = Qt::CTRL;
#else
  int SPi_CTRL = Qt::CTRL;
  int SPi_META = Qt::ALT;
#endif

  // basic navigation
  addKeyBinding(settings, QsciCommand::PageDown, Qt::Key_PageDown);
  addKeyBinding(settings, QsciCommand::PageUp, Qt::Key_PageUp);

  addKeyBinding(settings, QsciCommand::LineDown, Qt::Key_N | SPi_CTRL);
  addOtherKeyBinding(settings, QsciCommand::LineDown, Qt::Key_Down);
  addKeyBinding(settings, QsciCommand::LineDownExtend, Qt::Key_Down | Qt::SHIFT);
  addKeyBinding(settings, QsciCommand::LineUp, Qt::Key_P | SPi_CTRL);
  addOtherKeyBinding(settings, QsciCommand::LineUp, Qt::Key_Up);
  addKeyBinding(settings, QsciCommand::LineUpExtend, Qt::Key_Up | Qt::SHIFT);

  addKeyBinding(settings, QsciCommand::CharRight, Qt::Key_F | SPi_CTRL);
  addOtherKeyBinding(settings, QsciCommand::CharRight, Qt::Key_Right);
  addKeyBinding(settings, QsciCommand::CharRightExtend, Qt::Key_Right | Qt::SHIFT);

  addKeyBinding(settings, QsciCommand::WordRight, Qt::Key_F | SPi_META);
  addOtherKeyBinding(settings, QsciCommand::WordRight, Qt::Key_Right | SPi_CTRL);
  addKeyBinding(settings, QsciCommand::WordRightExtend, Qt::Key_Right | SPi_CTRL | Qt::SHIFT);

  addKeyBinding(settings, QsciCommand::CharLeft, Qt::Key_B | SPi_CTRL);
  addOtherKeyBinding(settings, QsciCommand::CharLeft, Qt::Key_Left);
  addKeyBinding(settings, QsciCommand::CharLeftExtend, Qt::Key_Left | Qt::SHIFT);

  addKeyBinding(settings, QsciCommand::WordLeft, Qt::Key_B | SPi_META);
  addOtherKeyBinding(settings, QsciCommand::WordLeft, Qt::Key_Left | SPi_CTRL);
  addKeyBinding(settings, QsciCommand::WordLeftExtend, Qt::Key_Left | SPi_CTRL | Qt::SHIFT);

  addKeyBinding(settings, QsciCommand::Delete, Qt::Key_D | SPi_CTRL);
  addOtherKeyBinding(settings, QsciCommand::Delete, Qt::Key_Delete);

  addKeyBinding(settings, QsciCommand::DeleteBack, Qt::Key_H | SPi_CTRL);
  addOtherKeyBinding(settings, QsciCommand::DeleteBack, Qt::Key_Backspace);

  addKeyBinding(settings, QsciCommand::Home, Qt::Key_A | SPi_CTRL);
  addKeyBinding(settings, QsciCommand::VCHome, Qt::Key_Home);
  addKeyBinding(settings, QsciCommand::VCHomeExtend, Qt::Key_Home | Qt::SHIFT);
  addKeyBinding(settings, QsciCommand::DocumentStart, Qt::Key_Home | SPi_CTRL);
  addKeyBinding(settings, QsciCommand::DocumentStartExtend, Qt::Key_Home | SPi_CTRL | Qt::SHIFT);

  addKeyBinding(settings, QsciCommand::LineEnd, Qt::Key_E | SPi_CTRL);
  addOtherKeyBinding(settings, QsciCommand::LineEnd, Qt::Key_End);
  addKeyBinding(settings, QsciCommand::LineEndExtend, Qt::Key_End | Qt::SHIFT);
  addKeyBinding(settings, QsciCommand::DocumentEnd, Qt::Key_End | SPi_CTRL);
  addKeyBinding(settings, QsciCommand::DocumentEndExtend, Qt::Key_End | SPi_CTRL | Qt::SHIFT);

  addKeyBinding(settings, QsciCommand::Delete, Qt::Key_D | SPi_CTRL);
  addKeyBinding(settings, QsciCommand::VerticalCentreCaret, Qt::Key_L | SPi_CTRL);

  // tab return
  addKeyBinding(settings, QsciCommand::Newline, Qt::Key_Return);

  addKeyBinding(settings, QsciCommand::Backtab, Qt::Key_Tab | Qt::SHIFT);

  // copy paste
  addKeyBinding(settings, QsciCommand::SelectionCopy, Qt::Key_C | SPi_META);
  addOtherKeyBinding(settings, QsciCommand::SelectionCopy, Qt::Key_C | SPi_CTRL);
  addKeyBinding(settings, QsciCommand::SelectionCut, Qt::Key_X | SPi_META);
  addOtherKeyBinding(settings, QsciCommand::SelectionCut, Qt::Key_X | SPi_CTRL);

  addKeyBinding(settings, QsciCommand::Paste, Qt::Key_V | SPi_META);
  addOtherKeyBinding(settings, QsciCommand::Paste, Qt::Key_Y | SPi_CTRL);
  addKeyBinding(settings, QsciCommand::Undo, Qt::Key_Z | SPi_META);
  addOtherKeyBinding(settings, QsciCommand::Undo, Qt::Key_Z | SPi_CTRL);
  addKeyBinding(settings, QsciCommand::Redo, Qt::Key_Z | Qt::SHIFT | SPi_META);
  addOtherKeyBinding(settings, QsciCommand::Redo, Qt::Key_Z | Qt::SHIFT | SPi_CTRL);
  addKeyBinding(settings, QsciCommand::SelectAll, Qt::Key_A | SPi_META);

  // delete word left and right
  addKeyBinding(settings, QsciCommand::DeleteWordLeft, Qt::Key_Backslash | SPi_META);
  addKeyBinding(settings, QsciCommand::DeleteWordLeft, Qt::Key_Backspace | SPi_META);
  addKeyBinding(settings, QsciCommand::DeleteWordRight, Qt::Key_D | SPi_META);

  standardCommands()->readSettings(settings);

  this->setMatchedBraceBackgroundColor(theme->color("MatchedBraceBackground"));
  this->setMatchedBraceForegroundColor(theme->color("MatchedBraceForeground"));

  setIndentationWidth(2);
  setIndentationGuides(true);
  setIndentationGuidesForegroundColor(theme->color("IndentationGuidesForeground"));
  setBraceMatching( SonicPiScintilla::SloppyBraceMatch);

  //TODO: add preference toggle for this:
  //this->setFolding(SonicPiScintilla::CircledTreeFoldStyle, 2);
  setCaretLineVisible(true);
  setCaretLineBackgroundColor(theme->color("CaretLineBackground"));
  setFoldMarginColors(theme->color("FoldMarginForeground"),theme->color("FoldMarginForeground"));
  setMarginLineNumbers(0, true);

  setMarginsBackgroundColor(theme->color("MarginBackground"));
  setMarginsForegroundColor(theme->color("MarginForeground"));
  setMarginsFont(QFont("Menlo", 15, -1, true));
  setUtf8(true);
  setText("#loading...");
  setLexer((QsciLexer *)lexer);

  setAutoCompletionThreshold(1);
  setAutoCompletionSource(SonicPiScintilla::AcsAPIs);
  setAutoCompletionCaseSensitivity(false);

  setSelectionBackgroundColor(theme->color("SelectionBackground"));
  setSelectionForegroundColor(theme->color("SelectionForeground"));
  setCaretWidth(5);
  setCaretForegroundColor(theme->color("CaretForeground"));
  setEolMode(EolUnix);

  SendScintilla(SCI_SETWORDCHARS, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:_?!");


}
void ChangeTileTerrain::initText() {
    setText(QCoreApplication::translate("Undo Commands",
                                        "Change Tile Terrain"));
}
void FolderListItem::setName(const QString& name)
{
    setText(0, name);
}
Exemple #9
0
void SubProjectItem::setDescription(QString desc)
{
    m_description = desc;
    setText(1, m_description);
}
Exemple #10
0
void KDatePickerPrivateYearSelector::setYear(int year)
{
  setText(QString::number(year));
}
Exemple #11
0
void KDatePickerPrivateWeekSelector::setWeek(int week)
{
  setText(QString::number(week));
}
Exemple #12
0
MainInfoItem::MainInfoItem(QListView *view, unsigned id)
        : ConfigItem(view, id)
{
    setText(0, i18n("User info"));
    setPixmap(0, Pict("info"));
}
void WSimpleManufacturerItem::setItemData(const hacc::TDBID &manufacturerIconID, const QString &manufacturerName)
{
    setIcon(0, 0, manufacturerIconID);
    setText(0, 0, manufacturerName);
}
SlitherBot::SlitherBot() :
    ui(new Ui::SlitherBot)
{
    ui->setupUi(this);
    connect(ui->tabWidget, SIGNAL(tabCloseRequested(int)), this, SLOT(closeTab(int)));
    //connect(ui->actionCreate, SIGNAL(triggered(bool)), this, SLOT(newInstance()));

    QToolBar *toolBar = new QToolBar;
    QLabel* nowPlaying = new QLabel();
    connect(&player, SIGNAL(nowPlaying(QString)), nowPlaying, SLOT(setText(QString)));
    toolBar->addWidget(nowPlaying);
    nowPlaying->setText("Now Playing: ...");

    QWidget* spacer = new QWidget();
    spacer->setMinimumWidth(12);
    toolBar->addWidget(spacer);

    QPushButton* button = new QPushButton();
    button->setText("New Tab");
    connect(button, SIGNAL(clicked(bool)), this, SLOT(newInstance()));
    toolBar->addWidget(button);

    button = new QPushButton();
    button->setText("Next Song");
    connect(button, SIGNAL(clicked(bool)), &player, SLOT(next()));
    toolBar->addWidget(button);

    button = new QPushButton();
    button->setText("Menu");
    connect(button, &QPushButton::clicked, [=]() {
        Menu menu(this);
        menu.setMessages(messages);
        menu.setXMPath(settings.value("xmpath", "").toString());
        menu.setTwitchChannel(settings.value("twitchchannel", "").toString());
        menu.setTwitchOAuth(settings.value("twitchoauth", "").toString());
        if(menu.exec() == QDialog::Accepted) {
            QString xmPath = menu.xmPath();
            QString twitchOAuth = menu.twitchOAuth();
            QString twitchChannel = menu.twitchChannel();
            QStringList messages = menu.messages();

            settings.setValue("xmpath", xmPath);
            settings.setValue("twitchoauth", twitchOAuth);
            settings.setValue("twitchchannel", twitchChannel);
            settings.setValue("messages", messages);

            emit updateMessages(messages);
            this->messages = messages;

            player.play(xmPath);
        }
    });
    toolBar->addWidget(button);

    ui->tabWidget->setCornerWidget(toolBar);

    QString xmPath = settings.value("xmpath").toString();
    if(!xmPath.isEmpty())
        player.play(xmPath);

    QString oauth = settings.value("twitchoauth").toString();
    QString channel = settings.value("twitchchannel").toString();
    if(!oauth.isEmpty() && !channel.isEmpty())
        twitchChat.connect(channel, oauth);

    messages = settings.value("messages").toStringList();

    QMetaObject::invokeMethod(&player, "next", Qt::QueuedConnection);
    QMetaObject::invokeMethod(this, "newInstance", Qt::QueuedConnection);
}
KLanguageButton::KLanguageButton( const QString &text, QWidget *parent )
  : QWidget( parent ),
    d( new KLanguageButtonPrivate(this) )
{
  setText(text);
}
void MarkdownEditorToolButton::setButtonId(ButtonId id)
{
    d->m_ButtonId = id;
    QImage img;
    QString tooltips;
    switch (id) {
    case ID_Bold:
        tooltips = QString::fromUtf8("Bold");
        img = QImage(QLatin1String(":/mdeditor/icons/bold.png"));
        break;
    case ID_Italic:
        tooltips = QString::fromUtf8("Italic");
        img = QImage(QLatin1String(":/mdeditor/icons/italic.png"));
        break;
    case ID_StrikeThrough:
        img = QImage(QLatin1String(":/mdeditor/icons/strikethrough.png"));
        tooltips = QString::fromUtf8("Strike Through");
        break;
    case ID_H1:
        setText(QString::fromUtf8("H1"));
        break;
    case ID_H2:
        setText(QString::fromUtf8("H2"));
        break;
    case ID_H3:
        setText(QString::fromUtf8("H3"));
        break;
    case ID_H4:
        setText(QString::fromUtf8("H4"));
        break;
    case ID_H5:
        setText(QString::fromUtf8("H5"));
        break;
    case ID_H6:
        setText(QString::fromUtf8("H6"));
        break;
    case ID_HorizonalRule:
        img = QImage(QLatin1String(":/mdeditor/icons/line.png"));
        tooltips = QString::fromUtf8("Horizonal Rule");
        break;
    case ID_Tastlist:
        img = QImage(QLatin1String(":/mdeditor/icons/tasklist.png"));
        tooltips = QString::fromUtf8("Task List");
        break;
    case ID_Link:
        img = QImage(QLatin1String(":/mdeditor/icons/link.png"));
        tooltips = QString::fromUtf8("Link");
        break;
    case ID_Image:
        img = QImage(QLatin1String(":/mdeditor/icons/image.png"));
        tooltips = QString::fromUtf8("Image");
        break;
    case ID_Table:
        img = QImage(QLatin1String(":/mdeditor/icons/table.png"));
        tooltips = QString::fromUtf8("Table");
        break;
    case ID_MathFormula:
        img = QImage(QLatin1String(":/mdeditor/icons/math.png"));
        tooltips = QString::fromUtf8("Math Formula");
        break;
    case ID_Code:
        img = QImage(QLatin1String(":/mdeditor/icons/code.png"));
        tooltips = QString::fromUtf8("Code");
        break;
    case ID_FlowChart:
        img = QImage(QLatin1String(":/mdeditor/icons/flow.png"));
        tooltips = QString::fromUtf8("Flow Chart");
        break;
    case ID_SequenceDiagram:
        img = QImage(QLatin1String(":/mdeditor/icons/sequence.png"));
        tooltips = QString::fromUtf8("Sequence Diagram");
        break;

    case ID_Help:
        img = QImage(QLatin1String(":/mdeditor/icons/help.png"));
        tooltips = QString::fromUtf8("Help Contents");
        break;
    default:
        break;
    }
    if(!img.isNull())
    {
        int h, s, v, a;
        for(int i = 0; i< img.width(); i++)
        {
            for(int j = 0; j < img.height(); j++)
            {
                QRgb rgb = img.pixel(i,j);
                QColor cl(rgb);
                cl.setAlpha(qAlpha(rgb));
                cl.getHsv(&h, &s, &v, &a);
                cl.setHsv(h, s, 255 - v, a);
                img.setPixel(i, j, cl.rgba());
            }
        }
        setIcon(QIcon(QPixmap::fromImage(img)));
    }
    setToolTip(tooltips);
}
CTrackUndoCommandPurgePts::CTrackUndoCommandPurgePts(CTrack *track)
: track(track)
{
    setText(QObject::tr("Purge Selection"));
}
Exemple #18
0
void kMyMoneyLineEdit::resetText()
{
  setText(d->m_text);
}
Exemple #19
0
scrolText::scrolText(QWidget *parent)
        :QWidget(parent),
        _opacity(1)
{
   setText(QString());
}
Exemple #20
0
void kMyMoneyLineEdit::loadText(const QString& text)
{
  d->m_text = text;
  setText(text);
}
void QtFontButton::setFont(const QFont & font)
{
	QWidget::setFont(font);
	setText(font);
	emit fontChanged(font);
}
Exemple #22
0
  /**
   * Constructor, creates and sets up widgets for this tool.
   *
   * @param parent
   */
  StatisticsTool::StatisticsTool(QWidget *parent) : Tool(parent) {
    p_boxSamps = 3;
    p_boxLines = 3;

    p_ulSamp = -1;
    p_ulLine = -1;

    p_set = false;

    p_dialog = new QDialog(parent);
    p_dialog->setWindowTitle("Statistics");

    p_visualBox = new QGroupBox("Visual Display");

    p_visualScroll = new QScrollArea;
    p_visualScroll->setBackgroundRole(QPalette::Dark);
    
    p_visualDisplay = new VisualDisplay(p_visualScroll);
    p_visualDisplay->setObjectName("dnDisplay");

    QCheckBox *checkBox = new QCheckBox("Hide Display");
    connect(checkBox, SIGNAL(toggled(bool)), this, SLOT(hideDisplay(bool)));

    QLabel *boxLabel = new QLabel("Box Size:");
    p_boxLabel = new QLabel;
    QString samps, lines;
    samps.setNum(p_boxSamps);
    lines.setNum(p_boxLines);
    p_boxLabel->setText(samps + "x" + lines);

    QHBoxLayout *boxLabelLayout = new QHBoxLayout;

    boxLabelLayout->addWidget(checkBox);
    boxLabelLayout->addStretch(1);
    boxLabelLayout->addWidget(boxLabel);
    boxLabelLayout->addWidget(p_boxLabel);

    QSlider *slider = new QSlider(Qt::Vertical);
    slider->setRange(2, 18);
    slider->setSliderPosition(10);
    slider->setSingleStep(1);
    slider->setTickInterval(1);
    slider->setTickPosition(QSlider::TicksBelow);
    connect(slider, SIGNAL(valueChanged(int)), p_visualDisplay, SLOT(setBoxSize(int)));
    connect(slider, SIGNAL(valueChanged(int)), this, SLOT(resizeScrollbars()));
    p_visualScroll->setWidget(p_visualDisplay);

    QGroupBox *displayMode = new QGroupBox("Display Mode");
    QRadioButton *displayText = new QRadioButton("Show Text");
    displayText->setToolTip("Display the pixels of a region as text");
    QRadioButton *displayPixels = new QRadioButton("Show Pixel Values");
    displayPixels->setToolTip("Display the pixels of a region");
    QRadioButton *displayDeviation = new QRadioButton("Show Deviation");
    displayDeviation->setToolTip("Display standard deviation over a region,\n where red denotes a larger deviation");

    QHBoxLayout *displayModeLayout = new QHBoxLayout;
    displayModeLayout->addWidget(displayText);
    displayModeLayout->addWidget(displayPixels);
    displayModeLayout->addWidget(displayDeviation);

    displayMode->setLayout(displayModeLayout);

    connect(displayText, SIGNAL(toggled(bool)), p_visualDisplay, SLOT(showText(bool)));
    connect(displayText, SIGNAL(toggled(bool)), slider, SLOT(setDisabled(bool)));
    connect(displayPixels, SIGNAL(toggled(bool)), p_visualDisplay, SLOT(showPixels(bool)));
    connect(displayDeviation, SIGNAL(toggled(bool)), p_visualDisplay, SLOT(showDeviation(bool)));

    displayText->setChecked(true);

    QHBoxLayout *visualHBoxLayout = new QHBoxLayout;
    visualHBoxLayout->addWidget(p_visualScroll);
    visualHBoxLayout->addWidget(slider);

    QVBoxLayout *visualVBoxLayout = new QVBoxLayout;
    visualVBoxLayout->addLayout(visualHBoxLayout);
    visualVBoxLayout->addWidget(displayMode);

    p_visualBox->setLayout(visualVBoxLayout);

    QGroupBox *statsBox = new QGroupBox("Statistics");

    p_minLabel = new QLabel("Minimum: n/a");
    p_minLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken);
    p_minLabel->setLineWidth(1);
    p_minLabel->setMargin(10);
    p_minLabel->setAlignment(Qt::AlignLeft);

    p_maxLabel = new QLabel("Maximum: n/a");
    p_maxLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken);
    p_maxLabel->setLineWidth(1);
    p_maxLabel->setMargin(10);
    p_maxLabel->setAlignment(Qt::AlignLeft);

    p_avgLabel = new QLabel("Average: n/a");
    p_avgLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken);
    p_avgLabel->setLineWidth(1);
    p_avgLabel->setMargin(10);
    p_avgLabel->setAlignment(Qt::AlignLeft);

    p_stdevLabel = new QLabel("Standard Dev: n/a");
    p_stdevLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken);
    p_stdevLabel->setLineWidth(1);
    p_stdevLabel->setMargin(10);
    p_stdevLabel->setAlignment(Qt::AlignLeft);

    p_dnLabel = new QLabel("DN: n/a");
    QFont labelFont = p_dnLabel->font();
    labelFont.setPointSize(8);
    p_dnLabel->setFont(labelFont);
    p_dnLabel->setAlignment(Qt::AlignRight);
    connect(p_visualDisplay, SIGNAL(setDn(QString)), p_dnLabel, SLOT(setText(QString)));

    p_sampLabel = new QLabel("Sample: n/a");
    p_sampLabel->setFont(labelFont);
    p_sampLabel->setAlignment(Qt::AlignLeft);
    connect(p_visualDisplay, SIGNAL(setSample(QString)), p_sampLabel, SLOT(setText(QString)));

    p_lineLabel = new QLabel("Line: n/a");
    p_lineLabel->setFont(labelFont);
    p_lineLabel->setAlignment(Qt::AlignCenter);
    connect(p_visualDisplay, SIGNAL(setLine(QString)), p_lineLabel, SLOT(setText(QString)));

    QGridLayout *statsLayout = new QGridLayout;
    statsLayout->addWidget(p_minLabel, 0, 0, 1, 2);
    statsLayout->addWidget(p_maxLabel, 1, 0, 1, 2);
    statsLayout->addWidget(p_avgLabel, 0, 2, 1, 2);
    statsLayout->addWidget(p_stdevLabel, 1, 2, 1, 2);
    statsLayout->addWidget(p_sampLabel, 2, 0);
    statsLayout->addWidget(p_lineLabel, 2, 1, 1, 2);
    statsLayout->addWidget(p_dnLabel, 2, 3);

    statsBox->setLayout(statsLayout);

    QVBoxLayout *dialogLayout = new QVBoxLayout;
    dialogLayout->addLayout(boxLabelLayout);
    dialogLayout->addWidget(p_visualBox);
    dialogLayout->addWidget(statsBox);

    p_dialog->setLayout(dialogLayout);

    checkBox->setChecked(true);
  }
Exemple #23
0
    void setInfo(const QString& l, const QString& d)
    {
	label = l;
	doc = d;
	setText(0,label);
    }
void CompleteLineEdit::keyPressEvent(QKeyEvent *e)
{
    if (!listView->isHidden())
    {
		int count = listView->model()->rowCount();	//一共有多少项
		QModelIndex currentIndex = listView->currentIndex();

		switch(e->key())
		{
			case Qt::Key_Down:
			{// 按向下方向键时,移动光标选中 下一个 完成列表中的项
				//qDebug()<<QString::fromUtf8("按下方向键下");
				int row = currentIndex.row() + 1;
				if (row >= count)
				{
					row = 0;
				}
				QModelIndex index = listView->model()->index(row, 0);
				listView->setCurrentIndex(index);
				break;
			}
			case Qt::Key_Up:
			{// 按向下方向键时,移动光标选中 上一个 完成列表中的项
				//qDebug()<<QString::fromUtf8("按下方向键上");
				int row = currentIndex.row() - 1;
				if (row < 0)
				{
					row = count - 1;
				}
				QModelIndex index = listView->model()->index(row, 0);
				listView->setCurrentIndex(index);
				break;
			}
			case Qt::Key_Escape:
			{// 按下Esc键时,隐藏完成列表
				listView->hide();
				break;
			}
			case Qt::Key_Return:
			{// 按下回车键时,使用完成列表中选中的项,并隐藏完成列表
				if (currentIndex.isValid())
				{
					QString text = listView->currentIndex().data().toString();
					setText(text);
				}
				listView->hide();
				qDebug()<<QString::fromUtf8("在这里调出流云的对话框~~");
				break;
			}
			default:
			{// 其他情况,隐藏完成列表,并使用QLineEdit的键盘按下事件
				listView->hide();
				QLineEdit::keyPressEvent(e);
				break;
			}
		}//end of switch
    }
    else
	{//嗯把其他的东西扔给基类总是明知的选择
        QLineEdit::keyPressEvent(e);
    }
}
Exemple #25
0
QT_BEGIN_NAMESPACE

/*!
    \class QUndoCommand
    \brief The QUndoCommand class is the base class of all commands stored on a QUndoStack.
    \since 4.2

    \inmodule QtWidgets

    For an overview of Qt's Undo Framework, see the
    \l{Overview of Qt's Undo Framework}{overview document}.

    A QUndoCommand represents a single editing action on a document; for example,
    inserting or deleting a block of text in a text editor. QUndoCommand can apply
    a change to the document with redo() and undo the change with undo(). The
    implementations for these functions must be provided in a derived class.

    \snippet code/src_gui_util_qundostack.cpp 0

    A QUndoCommand has an associated text(). This is a short string
    describing what the command does. It is used to update the text
    properties of the stack's undo and redo actions; see
    QUndoStack::createUndoAction() and QUndoStack::createRedoAction().

    QUndoCommand objects are owned by the stack they were pushed on.
    QUndoStack deletes a command if it has been undone and a new command is pushed. For example:

\snippet code/src_gui_util_qundostack.cpp 1

    In effect, when a command is pushed, it becomes the top-most command
    on the stack.

    To support command compression, QUndoCommand has an id() and the virtual function
    mergeWith(). These functions are used by QUndoStack::push().

    To support command macros, a QUndoCommand object can have any number of child
    commands. Undoing or redoing the parent command will cause the child
    commands to be undone or redone. A command can be assigned
    to a parent explicitly in the constructor. In this case, the command
    will be owned by the parent.

    The parent in this case is usually an empty command, in that it doesn't
    provide its own implementation of undo() and redo(). Instead, it uses
    the base implementations of these functions, which simply call undo() or
    redo() on all its children. The parent should, however, have a meaningful
    text().

    \snippet code/src_gui_util_qundostack.cpp 2

    Another way to create macros is to use the convenience functions
    QUndoStack::beginMacro() and QUndoStack::endMacro().

    \sa QUndoStack
*/

/*!
    Constructs a QUndoCommand object with the given \a parent and \a text.

    If \a parent is not 0, this command is appended to parent's child list.
    The parent command then owns this command and will delete it in its
    destructor.

    \sa ~QUndoCommand()
*/

QUndoCommand::QUndoCommand(const QString &text, QUndoCommand *parent)
{
    d = new QUndoCommandPrivate;
    if (parent != 0)
        parent->d->child_list.append(this);
    setText(text);
}
Exemple #26
0
/* 
 * EventWidget -- main widget for displaying events
 */
EventWidget::EventWidget( KDPEvent *_event, CalObject *_calendar,
			  QDate _date, QWidget *parent, char *_name )
  : QFrame( parent, _name )
{
  widgetEvent = _event;
  widgetDate = _date;
  calendar = _calendar;
  ASSERT(widgetEvent);

  // set up widgets.
  useHandle = TRUE;
  handleFrame = new QFrame(this, "handleFrame");
  handleFrame->setFrameStyle(Panel | Sunken);
  handleFrame->setLineWidth(2);
  handleFrame->setFixedWidth(HANDLESIZE);
  handleFrame->setMouseTracking(TRUE);
  handleFrame->setFocusProxy(this);

  textBox = new KTextBox(this, "textBox");
  textBox->setFrameStyle(NoFrame);
  textBox->setMouseTracking(TRUE);

  useIcons = TRUE;
  iconBox = new EWIconBoxFrame(this, "iconBox");
  iconBox->setFrameStyle(NoFrame);
  iconBox->setMinimumWidth(2*PMMARGIN+MAXPMSIZE);
  iconBox->setMouseTracking(TRUE);
  iconBox->setFocusProxy(this);

  // we filter ALL events.
  setFrameStyle(Box | Plain);
  setLineWidth(1);
  setFocusPolicy(ClickFocus);
  setMouseTracking(TRUE);
  installEventFilter(this);
  handleFrame->installEventFilter(this);
  textBox->installEventFilter(this);
  iconBox->installEventFilter(this);

  // set flags
  setState(NoState);
  // what type of resizing is going on
  ResizeStatus = 0;
  
  widgetSelected = FALSE;

  // RMB popup menu
  rmbPopup = new QPopupMenu();
  rmbPopup->insertItem(i18n("&Edit"));
  QPixmap pm = Icon("delete.xpm");
  rmbPopup->insertItem(pm, i18n("&Delete"));
  pm = Icon("bell.xpm");
  rmbPopup->insertItem(pm, i18n("Toggle Alarm"));
  connect(rmbPopup, SIGNAL(activated(int)), 
	  SLOT(popupSlot(int)));

  updateConfig();

  setSelected(FALSE);

  // set text
  if (!widgetEvent->getSummary().isEmpty())
    setText(widgetEvent->getSummary());

  if (widgetEvent->isReadOnly()) {
    setEnabled(FALSE);
    iconBox->setEnabled(FALSE);
    textBox->setEnabled(FALSE);
    setBackgroundColor(palette().disabled().base());
  }
}
Exemple #27
0
void* Speech_Load(Asset &asset) {
	auto speech = new SoLoud::Speech();
	speech->setText(asset.path);

	return (void*)speech;
}
Exemple #28
0
void MainWindow::setupDockWidgets(void)
{
	/* TODO: Do not create new dockWidgets if we already have them. */

	/* TODO: Kill any old dockWidgets before creating new ones? */

	for (int i = 0; i < getNumChannels(); ++i) {
		channelForms[i] = new ChannelForm(this);
		channelForms[i]->setChannelNumber(i);

		dockWidgets[i] = new QDockWidget(this);
		dockWidgets[i]->setAllowedAreas(Qt::BottomDockWidgetArea);

		QDockWidget::DockWidgetFeatures f;
		f = QDockWidget::DockWidgetClosable |
		    QDockWidget::DockWidgetMovable |
		    QDockWidget::DockWidgetFloatable;
		if (configChannelTitleBarLayout == DOCK_VERTICAL)
			f |= QDockWidget::DockWidgetVerticalTitleBar;
		dockWidgets[i]->setFeatures(f);
		dockWidgets[i]->setWidget(channelForms[i]);
		addDockWidget(Qt::BottomDockWidgetArea, dockWidgets[i],
			      Qt::Vertical);

		/* Update labels upon changes. */
		QObject::connect(channelForms[i],
			SIGNAL(sampleStartChanged(QString)),
			ui->labelSampleStart, SLOT(setText(QString)));
		QObject::connect(channelForms[i],
			SIGNAL(sampleEndChanged(QString)),
			ui->labelSampleEnd, SLOT(setText(QString)));
		QObject::connect(channelForms[i],
			SIGNAL(scaleFactorChanged(QString)),
			ui->labelScaleFactor, SLOT(setText(QString)));

		/* Redraw channels upon changes. */
		QObject::connect(channelForms[i],
			SIGNAL(sampleStartChanged(QString)),
			channelForms[i], SLOT(generatePainterPath()));
		QObject::connect(channelForms[i],
			SIGNAL(sampleEndChanged(QString)),
			channelForms[i], SLOT(generatePainterPath()));
		QObject::connect(channelForms[i],
			SIGNAL(scaleFactorChanged(QString)),
			channelForms[i], SLOT(generatePainterPath()));

		// dockWidgets[i]->show();

#if 0
		/* If the user renames a channel, adapt the dock title. */
		QObject::connect(lineEdits[i], SIGNAL(textChanged(QString)),
				 dockWidgets[i], SLOT(setWindowTitle(QString)));
#endif
	}

	/* For now, display only one scrollbar which scrolls all channels. */
	QDockWidget* scrollWidget = new QDockWidget(this);
	scrollWidget->setAllowedAreas(Qt::BottomDockWidgetArea);
	horizontalScrollBar = new QScrollBar(this);
	horizontalScrollBar->setOrientation(Qt::Horizontal);
	
	QDockWidget::DockWidgetFeatures f;
	if (configChannelTitleBarLayout == DOCK_VERTICAL)
		f |= QDockWidget::DockWidgetVerticalTitleBar;
	scrollWidget->setFeatures(f);
	scrollWidget->setWidget(horizontalScrollBar);
	addDockWidget(Qt::BottomDockWidgetArea, scrollWidget,
			      Qt::Vertical);
	
	for (int i = 0; i < getNumChannels(); ++i) {
		/* The scrollbar scrolls all channels. */
		connect(horizontalScrollBar, SIGNAL(valueChanged(int)),
				channelForms[i], SLOT(setScrollBarValue(int)));
	}
}
Exemple #29
0
// common function for wheel up/down and key up/down
// delta is in wheel units: a delta of 120 means to increment by 1
void
SpinBox::increment(int delta,
                   int shift) // shift = 1 means to increment * 10, shift = -1 means / 10
{
    bool ok;
    QString str = text();
    //qDebug() << "increment from " << str;
    const double oldVal = str.toDouble(&ok);
    
    if (!ok) {
        // Not a valid double value, don't do anything
        return;
    }
    
    bool useCursorPositionIncr = appPTR->getCurrentSettings()->useCursorPositionIncrements();
    
    // First, treat the standard case: use the Knob increment
    if (!useCursorPositionIncr) {
        double val = oldVal;
        _imp->currentDelta += delta;
        double inc = std::pow(10., shift) * _imp->currentDelta * _imp->increment / 120.;
        double maxiD = 0.;
        double miniD = 0.;
        switch (_imp->type) {
            case eSpinBoxTypeDouble: {
                maxiD = _imp->maxi.toDouble();
                miniD = _imp->mini.toDouble();
                val += inc;
                _imp->currentDelta = 0;
                break;
            }
            case eSpinBoxTypeInt: {
                maxiD = _imp->maxi.toInt();
                miniD = _imp->mini.toInt();
                val += (int)inc;     // round towards zero
                // Update the current delta, which contains the accumulated error
                _imp->currentDelta -= ( (int)inc ) * 120. / _imp->increment;
                assert(std::abs(_imp->currentDelta) < 120);
                break;
            }
        }
        val = std::max( miniD, std::min(val, maxiD) );
        if (val != oldVal) {
            setValue(val);
            Q_EMIT valueChanged(val);
        }
        
        return;
    }
    
    // From here on, we treat the positin-based increment.
    
    if ( (str.indexOf(QLatin1Char('e')) != -1) || (str.indexOf(QLatin1Char('E')) != -1) ) {
        // Sorry, we don't handle numbers with an exponent, although these are valid doubles
        return;
    }
    
    _imp->currentDelta += delta;
    int inc_int = _imp->currentDelta / 120; // the number of integert increments
    // Update the current delta, which contains the accumulated error
    _imp->currentDelta -= inc_int * 120;
    
    if (inc_int == 0) {
        // Nothing is changed, just return
        return;
    }
    
    // Within the value, we modify:
    // - if there is no selection, the first digit right after the cursor (or if it is an int and the cursor is at the end, the last digit)
    // - if there is a selection, the first digit after the start of the selection
    int len = str.size(); // used for chopping spurious characters
    if (len <= 0) {
        return; // should never happen
    }
    // The position in str of the digit to modify in str() (may be equal to str.size())
    int pos = ( hasSelectedText() ? selectionStart() : cursorPosition() );
    //if (pos == len) { // select the last character?
    //    pos = len - 1;
    //}
    // The position of the decimal dot
    int dot = str.indexOf(QLatin1Char('.'));
    if (dot == -1) {
        dot = str.size();
    }
    
    // Now, chop trailing and leading whitespace (and update len, pos and dot)
    
    // Leading whitespace
    while ( len > 0 && str[0].isSpace() ) {
        str.remove(0, 1);
        --len;
        if (pos > 0) {
            --pos;
        }
        --dot;
        assert(dot >= 0);
        assert(len > 0);
    }
    // Trailing whitespace
    while ( len > 0 && str[len - 1].isSpace() ) {
        str.remove(len - 1, 1);
        --len;
        if (pos > len) {
            --pos;
        }
        if (dot > len) {
            --dot;
        }
        assert(len > 0);
    }
    assert( oldVal == str.toDouble() ); // check that the value hasn't changed due to whitespace manipulation
    
    // On int types, there should not be any dot
    if ( (_imp->type == eSpinBoxTypeInt) && (len > dot) ) {
        // Remove anything after the dot, including the dot
        str.resize(dot);
        len = dot;
    }
    
    // Adjust pos so that it doesn't point to a dot or a sign
    assert( 0 <= pos && pos <= str.size() );
    while ( pos < str.size() &&
           (pos == dot || str[pos] == QLatin1Char('+') || str[pos] == QLatin1Char('-')) ) {
        ++pos;
    }
    assert(len >= pos);
    
    // Set the shift (may have to be done twice due to the dot)
    pos -= shift;
    if (pos == dot) {
        pos -= shift;
    }
    
    // Now, add leading and trailing zeroes so that pos is a valid digit position
    // (beware of the sign!)
    // Trailing zeroes:
    // (No trailing zeroes on int, of course)
    assert( len == str.size() );
    if ( (_imp->type == eSpinBoxTypeInt) && (pos >= len) ) {
        // If this is an int and we are beyond the last position, change the last digit
        pos = len - 1;
        // also reset the shift if it was negative
        if (shift < 0) {
            shift = 0;
        }
    }
    while ( pos >= str.size() ) {
        assert(_imp->type == eSpinBoxTypeDouble);
        // Add trailing zero, maybe preceded by a dot
        if (pos == dot) {
            str.append(QLatin1Char('.'));
            ++pos; // increment pos, because we just added a '.', and next iteration will add a '0'
            ++len;
        } else {
            assert(pos > dot);
            str.append(QLatin1Char('0'));
            ++len;
        }
        assert( pos >= (str.size() - 1) );
    }
    // Leading zeroes:
    bool hasSign = (str[0] == QLatin1Char('-') || str[0] == QLatin1Char('+'));
    while ( pos < 0 || ( pos == 0 && (str[0] == QLatin1Char('-') || str[0] == QLatin1Char('+')) ) ) {
        // Add leading zero
        str.insert(hasSign ? 1 : 0, QLatin1Char('0'));
        ++pos;
        ++dot;
        ++len;
    }
    assert( len == str.size() );
    assert( 0 <= pos && pos < str.size() && str[pos].isDigit() );
    
    QString noDotStr = str;
    int noDotLen = len;
    if (dot != len) {
        // Remove the dot
        noDotStr.remove(dot, 1);
        --noDotLen;
    }
    assert( (_imp->type == eSpinBoxTypeInt && noDotLen == dot) || noDotLen >= dot );
    double val = oldVal; // The value, as a double
    if (noDotLen > 16 && 16 >= dot) {
        // don't handle more than 16 significant digits (this causes over/underflows in the following)
        assert(noDotLen == noDotStr.size());
        noDotLen = 16;
        noDotStr.resize(noDotLen);
    }
    qlonglong llval = noDotStr.toLongLong(&ok); // The value, as a long long int
    if (!ok) {
        // Not a valid long long value, don't do anything
        return;
    }
    int llpowerOfTen = dot - noDotLen; // llval must be post-multiplied by this power of ten
    assert(llpowerOfTen <= 0);
    // check that val and llval*10^llPowerOfTen are close enough (relative error should be less than 1e-8)
    assert(std::abs(val * std::pow(10.,-llpowerOfTen) - llval) / std::max(qlonglong(1),std::abs(llval)) < 1e-8);
    
    
    // If pos is at the end
    if ( pos == str.size() ) {
        switch (_imp->type) {
            case eSpinBoxTypeDouble:
                if ( dot == str.size() ) {
                    str += QString::fromUtf8(".0");
                    len += 2;
                    ++pos;
                } else {
                    str += QLatin1Char('0');
                    ++len;
                }
                break;
            case eSpinBoxTypeInt:
                // take the character before
                --pos;
                break;
        }
    }
    
    // Compute the full value of the increment
    assert( len == str.size() );
    assert(pos != dot);
    assert( 0 <= pos && pos < len && str[pos].isDigit() );
    
    int powerOfTen = dot - pos - (pos < dot); // the power of ten
    assert( (_imp->type == eSpinBoxTypeDouble) || ( powerOfTen >= 0 && dot == str.size() ) );

    if (powerOfTen - llpowerOfTen > 16) {
        // too many digits to handle, don't do anything
        // (may overflow when adjusting llval)
        return;
    }

    double inc = inc_int * std::pow(10., (double)powerOfTen);
    
    // Check that we are within the authorized range
    double maxiD,miniD;
    switch (_imp->type) {
        case eSpinBoxTypeInt:
            maxiD = _imp->maxi.toInt();
            miniD = _imp->mini.toInt();
            break;
        case eSpinBoxTypeDouble:
        default:
            maxiD = _imp->maxi.toDouble();
            miniD = _imp->mini.toDouble();
            break;
    }
    val += inc;
    if ( (val < miniD) || (maxiD < val) ) {
        // out of the authorized range, don't do anything
        return;
    }

    // Adjust llval so that the increment becomes an int, and avoid rounding errors
    if (powerOfTen >= llpowerOfTen) {
        llval += inc_int * std::pow(10., powerOfTen - llpowerOfTen);
    } else {
        llval *= std::pow(10., llpowerOfTen - powerOfTen);
        llpowerOfTen -= llpowerOfTen - powerOfTen;
        llval += inc_int;
    }
    // check that val and llval*10^llPowerOfTen are still close enough (relative error should be less than 1e-8)
    assert(std::abs(val * std::pow(10.,-llpowerOfTen) - llval) / std::max(qlonglong(1),std::abs(llval)) < 1e-8);

    QString newStr;
    newStr.setNum(llval);
    bool newStrHasSign = newStr[0] == QLatin1Char('+') || newStr[0] == QLatin1Char('-');
    // the position of the decimal dot
    int newDot = newStr.size() + llpowerOfTen;
    // add leading zeroes if newDot is not a valid position (beware of sign!)
    while ( newDot <= int(newStrHasSign) ) {
        newStr.insert(int(newStrHasSign), QLatin1Char('0'));
        ++newDot;
    }
    assert( 0 <= newDot && newDot <= newStr.size() );
    assert( newDot == newStr.size() || newStr[newDot].isDigit() );
    if ( newDot != newStr.size() ) {
        assert(_imp->type == eSpinBoxTypeDouble);
        newStr.insert(newDot, QLatin1Char('.'));
    }
    // Check that the backed string is close to the wanted value (relative error should be less than 1e-8)
    assert( (newStr.toDouble() - val) / std::max(1e-8,std::abs(val)) < 1e-8 );
    // The new cursor position
    int newPos = newDot + (pos - dot);
    // Remove the shift (may have to be done twice due to the dot)
    newPos += shift;
    if (newPos == newDot) {
        // adjust newPos
        newPos += shift;
    }
    
    assert( 0 <= newDot && newDot <= newStr.size() );
    
    // Now, add leading and trailing zeroes so that newPos is a valid digit position
    // (beware of the sign!)
    // Trailing zeroes:
    while ( newPos >= newStr.size() ) {
        assert(_imp->type == eSpinBoxTypeDouble);
        // Add trailing zero, maybe preceded by a dot
        if (newPos == newDot) {
            newStr.append(QLatin1Char('.'));
        } else {
            assert(newPos > newDot);
            newStr.append(QLatin1Char('0'));
        }
        assert( newPos >= (newStr.size() - 1) );
    }
    // Leading zeroes:
    bool newHasSign = (newStr[0] == QLatin1Char('-') || newStr[0] == QLatin1Char('+'));
    while ( newPos < 0 || ( newPos == 0 && (newStr[0] == QLatin1Char('-') || newStr[0] == QLatin1Char('+')) ) ) {
        // add leading zero
        newStr.insert(newHasSign ? 1 : 0, QLatin1Char('0'));
        ++newPos;
        ++newDot;
    }
    assert( 0 <= newPos && newPos < newStr.size() && newStr[newPos].isDigit() );
    
    // Set the text and cursor position
    //qDebug() << "increment setting text to " << newStr;
    setText(newStr, newPos);
    // Set the selection
    assert( newPos + 1 <= newStr.size() );
    setSelection(newPos + 1, -1);
    Q_EMIT valueChanged( value() );
} // increment
Exemple #30
0
DIPElideLabel::DIPElideLabel(Qt::TextElideMode elideMode, const QString &text, QWidget *parent):QLabel(parent)
{
    mode = elideMode;
    if(!text.isNull()) setText(text);
    //update();
}