Beispiel #1
0
void Workbench::activated()
{
    if (!initialized) {
        QList<QToolBar*> bars = Gui::getMainWindow()->findChildren<QToolBar*>(QString::fromLatin1("Spreadsheet"));

        if (bars.size() == 1) {
            QToolBar * bar = bars[0];
            QtColorPicker * foregroundColor;
            QtColorPicker * backgroundColor;
            QPalette palette = Gui::getMainWindow()->palette();

            QList<QtColorPicker*> fgList = Gui::getMainWindow()->findChildren<QtColorPicker*>(QString::fromLatin1("Spreadsheet_ForegroundColor"));
            if (fgList.size() > 0)
                foregroundColor = fgList[0];
            else {
                foregroundColor = new QtColorPicker();
                foregroundColor->setObjectName(QString::fromLatin1("Spreadsheet_ForegroundColor"));
                foregroundColor->setStandardColors();
                foregroundColor->setCurrentColor(palette.color(QPalette::Foreground));
                QObject::connect(foregroundColor, SIGNAL(colorSet(QColor)), workbenchHelper.get(), SLOT(setForegroundColor(QColor)));
            }
            bar->addWidget(foregroundColor);

            QList<QtColorPicker*> bgList = Gui::getMainWindow()->findChildren<QtColorPicker*>(QString::fromLatin1("Spreadsheet_BackgroundColor"));
            if (bgList.size() > 0)
                backgroundColor = bgList[0];
            else {
                backgroundColor = new QtColorPicker();
                backgroundColor->setObjectName(QString::fromLatin1("Spreadsheet_BackgroundColor"));
                backgroundColor->setStandardColors();
                backgroundColor->setCurrentColor(palette.color(QPalette::Base));
                QObject::connect(backgroundColor, SIGNAL(colorSet(QColor)), workbenchHelper.get(), SLOT(setBackgroundColor(QColor)));
            }
            bar->addWidget(backgroundColor);

            initialized = false;
        }
    }
}
void XletSwitchBoard::mouseReleaseEvent(QMouseEvent *)
{
    // qDebug() << Q_FUNC_INFO;
    if (m_trace_box) {
        QRect rect = QRect(m_first_corner, m_second_corner).normalized();

        QRect gridRect = m_layout->getGridRect(rect);
        if ((gridRect.top() != gridRect.bottom()) &&
           (gridRect.right() != gridRect.left())) {
            QString name;
            QDialog dialog;
            dialog.setWindowTitle(tr("New group"));
            QVBoxLayout *layout = new QVBoxLayout(&dialog);
            layout->addWidget(new QLabel(tr("Please enter a name for the new group"), &dialog));
            QLineEdit *lineedit = new QLineEdit(&dialog);
            layout->addWidget(lineedit);
            layout->addWidget(new QLabel(tr("Please choose a color for the new group"), &dialog));
            QtColorPicker *colorpicker = new QtColorPicker(&dialog);
            colorpicker->setStandardColors();
            colorpicker->setCurrentColor(QColor(63, 63, 255));
            layout->addWidget(colorpicker);
            QDialogButtonBox *buttonbox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
                                                               Qt::Horizontal, &dialog);
            layout->addWidget(buttonbox);
            connect(buttonbox, SIGNAL(accepted()),
                    &dialog, SLOT(accept()) );
            connect(buttonbox, SIGNAL(rejected()),
                    &dialog, SLOT(reject()) );
            dialog.exec();
            if (dialog.result() == QDialog::Accepted)
                name = lineedit->text();
            if (!name.isEmpty()) {
                Group *group = new Group(this);
                group->setRect(gridRect);
                group->setName(name);
                group->setColor(colorpicker->currentColor());
                m_group_list.append(group);
                saveGroups();
            }
        }
        m_trace_box = false;
        update();
    }
    if (m_group_to_resize) {
        unsetCursor();
        m_group_to_resize = NULL;
    }
}