Beispiel #1
0
CodeArea::CodeArea(QWidget *parent)
    :QPlainTextEdit(parent)
    ,highlighter(this->document())
{
    QFont font;
    font.setFamily("Courier");
    font.setFixedPitch(true);
    font.setPointSize(10);
    font.insertSubstitution("	","    ");
    setFont(font);
    setWordWrapMode(QTextOption::NoWrap);

    lineNumberArea = new LineNumberArea(this);
    connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(updateLineNumberAreaWidth(int)));
    connect(this, SIGNAL(updateRequest(QRect,int)), this, SLOT(updateLineNumberArea(QRect,int)));
    connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(highlightCurrentLine()));

    updateLineNumberAreaWidth(0);
    highlightCurrentLine();
    mCompleter = new QCompleter(this);
    mCompleter->setModel(new QStringListModel(mWordList, mCompleter));
    mCompleter->setModelSorting(QCompleter::CaseSensitivelySortedModel);
    mCompleter->setCaseSensitivity(Qt::CaseSensitive);
    mCompleter->setWrapAround(false);

    mCompleter->setWidget(this);
    mCompleter->setCompletionMode(QCompleter::PopupCompletion);
    mCompleter->setCaseSensitivity(Qt::CaseInsensitive);
    QObject::connect(mCompleter, SIGNAL(activated(QString)),
                  this, SLOT(insertCompletion(QString)));

    connect(this,SIGNAL(textChanged()), this, SLOT(onTextChange()));
}
Beispiel #2
0
void UIWidget::setText(const std::string& text)
{
    if(m_text == text)
        return;

    std::string oldText = m_text;
    m_text = text;
    updateText();

    onTextChange(text, oldText);
}
QWidget* PropertyEditor::createWidgetForText(const QString& name, const QString& value, const QString& detail, QWidget* parent)
{
    mProperties[name] = value;
    QLineEdit *box = new QLineEdit(parent);
    if (!detail.isEmpty())
        box->setToolTip(detail);
    box->setObjectName(name);
    box->setText(value);
    connect(box, SIGNAL(textChanged(QString)), SLOT(onTextChange(QString)));
    return box;
}
Beispiel #4
0
QWidget* PropertyEditor::createWidgetForText(const QString& name, const QString& value, bool readOnly, const QString& detail, QWidget* parent)
{
    mProperties[name] = value;
    QWidget *w = 0;
    if (readOnly) {
        QLabel *label = new QLabel(parent);
        w = label;
        label->setText(value);
    } else {
        QLineEdit *box = new QLineEdit(parent);
        w = box;
        box->setText(value);
        connect(box, SIGNAL(textChanged(QString)), SLOT(onTextChange(QString)));
    }
    if (!detail.isEmpty())
        w->setToolTip(detail);
    w->setObjectName(name);
    return w;
}
Beispiel #5
0
qkeybutton::qkeybutton(QGraphicsItem *pItem,QWidget *parent) :
    QDialog(parent),
    ui(new Ui::qkeybutton)
{
    pCopyItem = NULL;
    ui->setupUi(this);
    setFixedSize(size());
    QPalette palette;
    palette.setColor(QPalette::Background, QColor(224,237,254));
    setPalette(palette);
    //setWindowOpacity(0.95);

    oId = -1;
    QGraphicsItem *Item;
    bInitFlag=false;
    tabWidget = new QTabWidget();
    pASCIIInputgen=new QKeyboardASCIIGen();

    ui->tabWidget->addTab(pASCIIInputgen, tr("外观设置"));
    pSecurityWight = new SecurityWidget;
    ui->tabWidget->addTab(pSecurityWight,tr("权限设置"));

    this->setWindowTitle(tr("键盘组件"));
    //建场景
    pScene = new QGraphicsScene(this);
    ui->LView->setScene(pScene);

    connect(pASCIIInputgen, SIGNAL(onDrawSence()),this, SLOT(onTextChange()));
    connect(pASCIIInputgen, SIGNAL(onKeypress(int)),this, SLOT(onKeypress(int)));
    connect(pASCIIInputgen, SIGNAL(addPicture(QGraphicsItem*,QPixmap*)),this, SLOT(onAddPicture(QGraphicsItem*,QPixmap*)));
    if(pItem)
    {
        Item = dynamic_cast<KeyBoardItem *> (pItem)->Clone();
        InitAllProperty(dynamic_cast<KeyBoardItem *> (Item));
    }
    else
    {
        InitAllProperty(NULL);
    }
    ui->accept->setFocus(Qt::MouseFocusReason);
    bInitFlag=true;
}
Beispiel #6
0
void PythonEditorWidget::buildWidget() {
    setWindowIcon(QIcon(":/icons/python.png"));
    QWidget* content = new QWidget(this);
    QVBoxLayout* verticalLayout = new QVBoxLayout(content);
    ////Create Buttons
    QHBoxLayout* horizontalLayout = new QHBoxLayout();
    QToolButton* runButton = new QToolButton(content);
    QToolButton* newButton = new QToolButton(content);
    QToolButton* openButton = new QToolButton(content);
    QToolButton* saveButton = new QToolButton(content);
    QToolButton* saveAsButton = new QToolButton(content);
    QPushButton* clearOutputButton = new QPushButton(content);
    runButton->setShortcut(QKeySequence(tr("F5")));
    runButton->setIcon(QIcon(":/icons/python.png"));
    runButton->setToolTip("Compile and run (F5)");
    newButton->setIcon(QIcon(":/icons/new.png"));
    newButton->setToolTip("New file (Ctrl+N)");
    openButton->setIcon(QIcon(":/icons/open.png"));
    openButton->setToolTip("Open Python script");
    saveButton->setIcon(QIcon(":/icons/save.png"));
    saveButton->setToolTip("Save (Ctrl+S)");
    saveAsButton->setIcon(QIcon(":/icons/saveas.png"));
    saveAsButton->setToolTip("Save as");
    clearOutputButton->setText("Clear Output");
   
    QFrame* line1 = new QFrame(content);
    line1->setFrameShape(QFrame::VLine);
    line1->setFrameShadow(QFrame::Sunken);
    QFrame* line2 = new QFrame(content);
    line2->setFrameShape(QFrame::VLine);
    line2->setFrameShadow(QFrame::Sunken);
    QFrame* line3 = new QFrame(content);
    line3->setFrameShape(QFrame::VLine);
    line3->setFrameShadow(QFrame::Sunken);
    horizontalLayout->addWidget(runButton);
    horizontalLayout->addWidget(line1);
    horizontalLayout->addWidget(newButton);
    horizontalLayout->addWidget(openButton);
    horizontalLayout->addWidget(saveButton);
    horizontalLayout->addWidget(saveAsButton);
    horizontalLayout->addWidget(line2);
    horizontalLayout->addWidget(clearOutputButton);
    horizontalLayout->addWidget(line3);
    QSpacerItem* horizontalSpacer =
        new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
    horizontalLayout->addItem(horizontalSpacer);
    // Done creating buttons
    QSplitter* splitter = new QSplitter(content);

    splitter->setOrientation(Qt::Vertical);
    pythonCode_ = new PythonTextEditor(content);
    pythonCode_->setObjectName("pythonEditor");
    pythonCode_->setUndoRedoEnabled(true);
    setDefaultText();
    pythonOutput_ = new QTextEdit(content);
    pythonOutput_->setObjectName("pythonConsole");
    pythonOutput_->setReadOnly(true);
    pythonOutput_->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
    syntaxHighligther_ =
        SyntaxHighligther::createSyntaxHighligther<Python>(pythonCode_->document());
    verticalLayout->addLayout(horizontalLayout);
    splitter->addWidget(pythonCode_);
    splitter->addWidget(pythonOutput_);
    splitter->setStretchFactor(0, 1);
    splitter->setStretchFactor(1, 0);
    splitter->setHandleWidth(2);
    // enable QSplitter:hover stylesheet 
    // QTBUG-13768 https://bugreports.qt.io/browse/QTBUG-13768
    splitter->handle(1)->setAttribute(Qt::WA_Hover);

    verticalLayout->addWidget(splitter);
    setWidget(content);
    connect(pythonCode_, SIGNAL(textChanged()), this, SLOT(onTextChange()));
    connect(runButton, SIGNAL(clicked()), this, SLOT(run()));
    connect(newButton, SIGNAL(clicked()), this, SLOT(setDefaultText()));
    connect(openButton, SIGNAL(clicked()), this, SLOT(open()));
    connect(saveButton, SIGNAL(clicked()), this, SLOT(save()));
    connect(saveAsButton, SIGNAL(clicked()), this, SLOT(saveAs()));
    connect(clearOutputButton, SIGNAL(clicked()), this, SLOT(clearOutput()));


    updateStyle();
    InviwoApplication::getPtr()->getSettingsByType<SystemSettings>()->pythonSyntax_.onChange(this, &PythonEditorWidget::updateStyle);
    InviwoApplication::getPtr()->getSettingsByType<SystemSettings>()->pyFontSize_.onChange(this, &PythonEditorWidget::updateStyle);
}
Beispiel #7
0
void TextWidget::setText(std::string text)
{
	setTextSilent(text);
	onTextChange();
}
PythonEditorWidget::PythonEditorWidget(InviwoMainWindow* ivwwin, InviwoApplication* app)
    : InviwoDockWidget(tr("Python Editor"), ivwwin)
    , settings_("Inviwo", "Inviwo")
    , infoTextColor_(153, 153, 153)
    , errorTextColor_(255, 107, 107)
    , runAction_(nullptr)
    , script_()
    , unsavedChanges_(false)
    , app_(app)
    , appendLog_(true)
{

    setObjectName("PythonEditor");
    settings_.beginGroup("PythonEditor");
    QString lastFile = settings_.value("lastScript", "").toString();
    appendLog_ = settings_.value("appendLog", appendLog_).toBool();
    settings_.endGroup();
    setVisible(false);
    setWindowIcon(QIcon(":/icons/python.png"));

    QMainWindow* mainWindow = new QMainWindow();
    mainWindow->setContextMenuPolicy(Qt::NoContextMenu);
    QToolBar* toolBar = new QToolBar();
    mainWindow->addToolBar(toolBar);
    toolBar->setFloatable(false);
    toolBar->setMovable(false);
    setWidget(mainWindow);

    {
        runAction_ = toolBar->addAction(QIcon(":/icons/python.png"), "Compile and Run");
        runAction_->setShortcut(QKeySequence(tr("F5")));
        runAction_->setShortcutContext(Qt::WidgetWithChildrenShortcut);
        runAction_->setToolTip("Compile and Run Script");
        mainWindow->addAction(runAction_);
        connect(runAction_, &QAction::triggered, [this]() {run(); });
    }
    {
        auto action = toolBar->addAction(QIcon(":/icons/new.png"), tr("&New Script"));
        action->setShortcut(QKeySequence::New);
        action->setShortcutContext(Qt::WidgetWithChildrenShortcut);
        action->setToolTip("New Script");
        mainWindow->addAction(action);
        connect(action, &QAction::triggered, [this](){setDefaultText();});
    }
    {
        auto action = toolBar->addAction(QIcon(":/icons/open.png"), tr("&Open Script"));
        action->setShortcut(QKeySequence::Open);
        action->setShortcutContext(Qt::WidgetWithChildrenShortcut);
        action->setToolTip("Open Script");
        mainWindow->addAction(action);
        connect(action, &QAction::triggered, [this](){open();});
    }

    {
        auto action = toolBar->addAction(QIcon(":/icons/save.png"), tr("&Save Script"));
        action->setShortcut(QKeySequence::Save);
        action->setShortcutContext(Qt::WidgetWithChildrenShortcut);
        action->setToolTip("Save Script");
        mainWindow->addAction(action);
        connect(action, &QAction::triggered, [this](){save();});
    }
    {
        auto action = toolBar->addAction(QIcon(":/icons/saveas.png"), tr("&Save Script As..."));
        action->setShortcut(QKeySequence::SaveAs);
        action->setShortcutContext(Qt::WidgetWithChildrenShortcut);
        action->setToolTip("Save Script As...");
        mainWindow->addAction(action);
        connect(action, &QAction::triggered, [this](){saveAs();});
    }
    {
        QIcon icon;
        icon.addFile(":/icons/log-append.png", QSize(), QIcon::Normal, QIcon::On);
        icon.addFile(":/icons/log-clearonrun.png", QSize(), QIcon::Normal, QIcon::Off);

        QString str = (appendLog_ ? "Append Log" : "Clear Log on Run");
        auto action = toolBar->addAction(icon, str);
        action->setShortcut(Qt::ControlModifier + Qt::Key_E);
        action->setShortcutContext(Qt::WidgetWithChildrenShortcut);
        action->setCheckable(true);
        action->setChecked(appendLog_);
        action->setToolTip(appendLog_ ? "Append Log" : "Clear Log on Run");
        mainWindow->addAction(action);
        connect(action, &QAction::toggled, [this, action](bool toggle) { 
            appendLog_ = toggle; 
            // update tooltip and menu entry
            QString tglstr = (toggle ? "Append Log" : "Clear Log on Run");
            action->setText(tglstr);
            action->setToolTip(tglstr);
            // update settings
            settings_.beginGroup("PythonEditor");
            settings_.setValue("appendLog", appendLog_);
            settings_.endGroup();
        });
    }
    {
        auto action = toolBar->addAction(QIcon(":/icons/log-clear.png"), "Clear Log Output");
        action->setShortcut(Qt::ControlModifier + Qt::Key_E);
        action->setShortcutContext(Qt::WidgetWithChildrenShortcut);
        action->setToolTip("Clear Log Output");
        mainWindow->addAction(action);
        connect(action, &QAction::triggered, [this](){clearOutput();});
    }

    // Done creating buttons
    QSplitter* splitter = new QSplitter(nullptr);
    splitter->setOrientation(Qt::Vertical);
    pythonCode_ = new PythonTextEditor(nullptr);
    pythonCode_->setObjectName("pythonEditor");
    pythonCode_->setUndoRedoEnabled(true);
    setDefaultText();
    pythonOutput_ = new QTextEdit(nullptr);
    pythonOutput_->setObjectName("pythonConsole");
    pythonOutput_->setReadOnly(true);
    pythonOutput_->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
    syntaxHighligther_ =
        SyntaxHighligther::createSyntaxHighligther<Python>(pythonCode_->document());

    splitter->addWidget(pythonCode_);
    splitter->addWidget(pythonOutput_);
    splitter->setStretchFactor(0, 1);
    splitter->setStretchFactor(1, 0);
    splitter->setHandleWidth(2);
    // enable QSplitter:hover stylesheet
    // QTBUG-13768 https://bugreports.qt.io/browse/QTBUG-13768
    splitter->handle(1)->setAttribute(Qt::WA_Hover);
    mainWindow->setCentralWidget(splitter);

    QObject::connect(pythonCode_, SIGNAL(textChanged()), this, SLOT(onTextChange()));
    // close this window before the main window is closed
    QObject::connect(ivwwin, &InviwoMainWindow::closingMainWindow, [this]() { delete this; });

    this->updateStyle();

    
    this->resize(500, 700);

    if (app_) {
        app_->getSettingsByType<SystemSettings>()->pythonSyntax_.onChange(
            this, &PythonEditorWidget::updateStyle);
        app_->getSettingsByType<SystemSettings>()->pyFontSize_.onChange(
            this, &PythonEditorWidget::updateStyle);
        app_->registerFileObserver(this);
    }
    unsavedChanges_ = false;

    if (lastFile.size() != 0) loadFile(lastFile.toLocal8Bit().constData(), false);

    setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
    setFloating(true);
}
Beispiel #9
0
kd::kd()
{
    ready_to_die = false;

    /* Creating top-right area (Line input and button) */
    item_input = new QLineEdit;
    item_button = new QPushButton(tr("Add"));
    item_button->setDefault(true);
    bottom_h_layout = new QHBoxLayout;
    bottom_h_layout->addWidget(item_input);
    bottom_h_layout->addWidget(item_button);

    items_tree = new QTreeWidget;
    items_tree->setColumnCount(2);
    items_tree->setHeaderLabels(QStringList() << tr("Goods") << tr("Price") );

    added_items = new QTextBrowser;
    central_widget = new QSplitter;
    central_widget->addWidget(items_tree);
    central_widget->addWidget(added_items);
    central_widget->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);

    /* Create right side (top area, suggest label and list of added items) */
    item_suggest = new QLabel;
    right_v_layout = new QVBoxLayout;
    right_v_layout->addWidget(item_suggest);
    right_v_layout->addWidget(central_widget);
    right_v_layout->addLayout(bottom_h_layout);
    right_widget = new QWidget;
    right_widget->setLayout(right_v_layout);

    setCentralWidget( right_widget );
    item_input->setFocus();

    /* Restore window settings */
    app_settings = new QSettings(QSettings::IniFormat, QSettings::UserScope, "Stinky", "Celtic House Menu");
    app_settings->beginGroup("MainWindow");
    resize(app_settings->value("Size", QSize(400, 400)).toSize());
    move(app_settings->value("Position", QPoint(200, 200)).toPoint());
    central_widget->restoreState( app_settings->value("Splitter").toByteArray() );
    app_settings->endGroup();

    menu_file = new QSettings(QSettings::IniFormat, QSettings::SystemScope, "Stinky", "Celtic House Menu");
    qDebug() << "Menu in " << menu_file->fileName();
    cards = new QSettings(QSettings::IniFormat, QSettings::SystemScope, "Stinky", "cards");
    qDebug() << "Menu in " << cards->fileName();
    // Cards debug
    QStringList ckeys = cards->allKeys();
    for(int i = 0; i < ckeys.size(); ++i) {
        qDebug() << "Value:" << ckeys.at(i) << " = " << QString::fromUtf8( cards->value( ckeys.at(i), "Ы" ).toString().toAscii() );
    }

    QString logs_dir = menu_file->value("Settings/LogsDir", "").toString();
    if(logs_dir.length() > 1)
        logger = new Logger(logs_dir);
    else
        logger = new Logger;
    QString errmsg;
    if(logger->getError(errmsg) != QFile::NoError)
    {
        QMessageBox msgBox;
        msgBox.setIcon(QMessageBox::Critical);
        msgBox.setText(tr("Can not open log file."));
        msgBox.setInformativeText(errmsg);
        msgBox.exec();
        ready_to_die = true;
        return;
    }

    // readMenu
    QString tmpstr = QString("root");
    readMenu(*items_tree->invisibleRootItem(), tmpstr, tmpstr);
    tmpstr = QString("launcher");
    QTreeWidgetItem *tmpitem = new QTreeWidgetItem;

    QBrush *red = new QBrush(Qt::red);
    tmpitem->setForeground(0, *red);
    readMenu(*tmpitem, tmpstr, tmpstr);
    tmpitem->setText( 2, "/" );
    items_tree->addTopLevelItem(tmpitem);
    /*End read menu*/

    items_tree->expandAll();
    items_tree->resizeColumnToContents(1);
    items_tree->resizeColumnToContents(0);
    items_tree->collapseAll();
    totalprice = 0;

    QAction* a_quit = new QAction(this);
    QAction* a_rotate = new QAction(this);
    a_quit->setText( "Quit" );
    a_rotate->setText( "Rotate" );

    QMenu *filemenu = menuBar()->addMenu( "File" );
    filemenu->addAction( a_quit );
    filemenu->addAction( a_rotate );
    //status_bar = new QStatusBar(central_widget);
    //statusBar();
    updateCurrentTotal();

    connect(a_quit, SIGNAL(triggered()), SLOT(close()) );
    connect(a_rotate, SIGNAL(triggered()), SLOT(onRotate()) );
    connect(item_button, SIGNAL(clicked()), SLOT(onAddButtonPress()) );
    connect(item_input, SIGNAL(returnPressed()), SLOT(onAddButtonPress()) );
    connect(item_input, SIGNAL(textChanged(QString)), SLOT(onTextChange(QString)) );
    connect(items_tree, SIGNAL(itemClicked(QTreeWidgetItem*,int)), SLOT(onItemClick(QTreeWidgetItem*,int)) );
    connect(items_tree, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)), SLOT(onDoubleClick(QTreeWidgetItem*,int)) );
}
Beispiel #10
0
Login::Login(QWidget *parent) : Dialog(parent), _passInput(Tr("PassCode"), this), _generator(QCryptographicHash::Algorithm::Sha3_512) {
	_layout.addWidget(&_passInput);
	setLayout(&_layout);
	QObject::connect(&_passInput, SIGNAL(textChanged(QString)), this, SLOT(onTextChange(QString)));
}