コード例 #1
0
ファイル: LCLocaleDialog.cpp プロジェクト: AOSC-Dev/calamares
LCLocaleDialog::LCLocaleDialog( const QString& guessedLCLocale,
                                const QStringList& localeGenLines,
                                QWidget* parent )
    : QDialog( parent )
{
    setModal( true );
    setWindowTitle( tr( "System locale setting" ) );

    QBoxLayout* mainLayout = new QVBoxLayout;
    setLayout( mainLayout );

    QLabel* upperText = new QLabel( this );
    upperText->setWordWrap( true );
    upperText->setText( tr( "The system locale setting affects the language and character "
                            "set for some command line user interface elements.<br/>"
                            "The current setting is <strong>%1</strong>." )
                            .arg( guessedLCLocale ) );
    mainLayout->addWidget( upperText );
    setMinimumWidth( upperText->fontMetrics().height() * 24 );

    m_localesWidget = new QListWidget( this );
    m_localesWidget->addItems( localeGenLines );
    m_localesWidget->setSelectionMode( QAbstractItemView::SingleSelection );
    mainLayout->addWidget( m_localesWidget );

    int selected = -1;
    for ( int i = 0; i < localeGenLines.count(); ++i )
    {
        if ( localeGenLines[ i ].contains( guessedLCLocale ) )
        {
            selected = i;
            break;
        }
    }

    QDialogButtonBox* dbb = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
                                                  Qt::Horizontal,
                                                  this );
    mainLayout->addWidget( dbb );

    connect( dbb->button( QDialogButtonBox::Ok ), &QPushButton::clicked,
             this, &QDialog::accept );
    connect( dbb->button( QDialogButtonBox::Cancel ), &QPushButton::clicked,
             this, &QDialog::reject );

    connect( m_localesWidget, &QListWidget::itemSelectionChanged,
             [this, dbb]()
    {
        if ( m_localesWidget->selectedItems().isEmpty() )
            dbb->button( QDialogButtonBox::Ok )->setEnabled( false );
        else
            dbb->button( QDialogButtonBox::Ok )->setEnabled( true );

    } );

    if ( selected > -1 )
    {
        m_localesWidget->setCurrentRow( selected );
    }
}
コード例 #2
0
ファイル: progressview.cpp プロジェクト: Omega9/synthclone
void
ProgressView::setStatus(const QString &status)
{
    QLabel *label = this->status;
    label->setText(label->fontMetrics().elidedText(status, Qt::ElideRight,
                                                   label->width()));
}
コード例 #3
0
ファイル: slider.cpp プロジェクト: milkmiruku/qmidiarp
Slider::Slider(int minValue, int maxValue, int pageStep, int tickStep,
        int value, Qt::Orientation orientation, const QString& label,
        QWidget * parent): QWidget(parent)
{
    slider = new QSlider(orientation, parent);
    slider->setTickInterval(tickStep);
    slider->setTickPosition(QSlider::TicksLeft);
    slider->setRange(minValue, maxValue);
    slider->setSingleStep(pageStep);
    slider->setValue(value);
    if (orientation == Qt::Vertical) {
        slider->setMinimumHeight(150);
    }
    else {
        slider->setMinimumWidth(150);
    }
    connect(slider, SIGNAL(valueChanged(int)), this, SLOT(updateSpinBox(int)));
    connect(slider, SIGNAL(sliderMoved(int)), this, SLOT(fillSpinBox(int)));

    sliderSpin = new QSpinBox(this);
    sliderSpin->setRange(minValue, maxValue);
    sliderSpin->setValue(value);
    sliderSpin->setKeyboardTracking(false);
    connect(sliderSpin, SIGNAL(valueChanged(int)), slider, SLOT(setValue(int)));
    connect(sliderSpin, SIGNAL(editingFinished()), this, SLOT(emitAsMoved()));

    QLabel* sliderLabel = new QLabel(this);
    sliderLabel->setText(label);
    sliderLabel->setBuddy(sliderSpin);
    sliderLabel->setMinimumWidth(5*sliderLabel->fontMetrics().maxWidth());
    QBoxLayout *sliderLayout = new QBoxLayout(QBoxLayout::LeftToRight,this);
    sliderLayout->setMargin(0);
    sliderLayout->addWidget(sliderLabel);
    sliderLayout->addWidget(slider);
    sliderLayout->addSpacing(2);
    sliderLayout->addWidget(sliderSpin);
    if (orientation == Qt::Vertical) {
        sliderLayout->setDirection(QBoxLayout::TopToBottom);
        sliderLayout->setAlignment(Qt::AlignHCenter);
    }
    else {
        sliderLayout->setDirection(QBoxLayout::LeftToRight);
        sliderLayout->setAlignment(Qt::AlignTop);
    }
    setMinimumWidth(155 + sliderLabel->width() + sliderLabel->fontMetrics().maxWidth() * 3);
    setLayout(sliderLayout);
}
コード例 #4
0
void NotificationDialog::getDataFromDatabase(){
    ui->tableWidget->setRowCount(0);
    bool disconnect = false;
    bool connected = true;
    if(!db.isOpen()){
        disconnect = true;
        connected = parent->connectToDatabase(&db, false, this);
    }
    if(connected){
        for(int i = 0; i < parent->cNotifications.size(); i++){
            QLabel * item = new QLabel;
            QStringList columnNames = parent->getColumnsNames("Customers");
            QVector<QStringList> retrievedData = parent->executeSelectCommand("Customers", columnNames, "ID=" + QString::number(parent->cNotifications[i].customer));
            if(!retrievedData.isEmpty()){
                if(!retrievedData[0].isEmpty()){
                    item->setText(retrievedData[columnNames.indexOf("Surname")][0] + " " + retrievedData[columnNames.indexOf("Name")][0] + " " + retrievedData[columnNames.indexOf("Patronomic")][0] + "\nТелефонный номер: (" + retrievedData[columnNames.indexOf("PhoneCode")][0] + ")" + retrievedData[columnNames.indexOf("PhoneNumber")][0] + "\nПО: " + parent->cNotifications[i].soft + "\nДата истечения лицензии: " + parent->cNotifications[i].date);
                    QFontMetrics fontMetrics = item->fontMetrics();
                    QSize textSize = fontMetrics.size(0, item->text());
                    int textWidth = textSize.width() + 30;
                    int textHeight = textSize.height() + 20;
                    item->setMinimumSize(textWidth, textHeight);
                    item->resize(textWidth, textHeight);
                    ui->tableWidget->setRowCount(ui->tableWidget->rowCount() + 1);
                    ui->tableWidget->setCellWidget(ui->tableWidget->rowCount() - 1, 0, item);
                    ui->tableWidget->setRowHeight(ui->tableWidget->rowCount() - 1, textHeight);
                }
            }
        }
        for(int i = 0; i < parent->lNotifications.size(); i++){
            QLabel * item = new QLabel;
            item->setText("ПО: " + parent->lNotifications[i].soft + "\nОсталось лицензий: " + QString::number(parent->lNotifications[i].count));
            QFontMetrics fontMetrics = item->fontMetrics();
            QSize textSize = fontMetrics.size(0, item->text());
            int textWidth = textSize.width() + 30;
            int textHeight = textSize.height() + 20;
            item->setMinimumSize(textWidth, textHeight);
            item->resize(textWidth, textHeight);
            ui->tableWidget->setRowCount(ui->tableWidget->rowCount() + 1);
            ui->tableWidget->setCellWidget(ui->tableWidget->rowCount() - 1, 0, item);
            ui->tableWidget->setRowHeight(ui->tableWidget->rowCount() - 1, textHeight);
        }
    }
    if(disconnect)
        parent->disconnectFromDatabase(&db);
}
コード例 #5
0
ファイル: lyricwidget.cpp プロジェクト: Argun/doubanfm-qt
void LyricWidget::setLyric(const QLyricList &lyric) {
    if (animWidget) delete animWidget;
    animWidget = new QWidget(this);
    animWidget->raise();
    ui->border->raise();
    QRect geo = this->geometry();
    animWidget->setMinimumWidth(geo.width());
    animWidget->setMaximumWidth(geo.width());
    animWidget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);

    QVBoxLayout *vbox = new QVBoxLayout(animWidget);
    vbox->setMargin(0);
    vbox->setSpacing(0);
    vbox->setContentsMargins(0, 0, 0, 0);
    animWidget->setLayout(vbox);

    labels.clear();
    curInd = 0;
    this->lyric = lyric;
    firstShowing = false;

    int widgetWidth = this->geometry().width();
    int accuHeight = 0;
    for (const QLyric& lyr : lyric) {
        QLabel *label = new QLabel(animWidget);
        QFont font("文泉驿微米黑", 11);
        font.setStyleStrategy(QFont::PreferAntialias);
        label->setFont(font);
        label->setText(QString("<font color='grey'>") +
                        lyr.lyric + QString("</font>"));
        label->setMaximumWidth(widgetWidth);
        label->setMaximumWidth(widgetWidth);
        label->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
        label->setWordWrap(true);
        labels.append(label);
        QRect fsize = label->fontMetrics().boundingRect(label->text());
        int height = (widgetWidth + fsize.width()) / widgetWidth * fsize.height() + 15;
        heights.append(height);
        label->setMinimumHeight(height);
        label->setMaximumHeight(height);
        accuHeight += height;

        animWidget->layout()->addWidget(label);
    }

    if (heights.size() > 0) {
        animWidget->setGeometry(0, this->geometry().height() / 2 + heights[0],
                                this->geometry().width(), accuHeight);
    }
    animWidget->show();
    ui->border->setText("");
}
コード例 #6
0
ファイル: gui.cpp プロジェクト: aemanov/seiscomp3
		bool eventFilter(QObject *obj, QEvent *event) {
			if ( event->type() == QEvent::Paint ) {
				QLabel *l = static_cast<QLabel*>(obj);
				QPainter painter(l);

				painter.fillRect(l->rect(), midBg);

				/*
				painter.setPen(Qt::black);
				painter.drawLine(0,0,0,l->height());
				painter.drawLine(0,l->height()-1,l->width(),l->height()-1);
				*/
				painter.setPen(normalText);

				int tw = l->fontMetrics().width(l->text());
				QRect tr = l->rect().adjusted(20,0,-20,0);

				if ( tw > tr.width() ) {
					QPixmap pixmap(tr.size());
					pixmap.fill(Qt::transparent);

					QPainter p(&pixmap);
					p.setPen(painter.pen());
					p.setFont(painter.font());

					p.drawText(pixmap.rect(), l->alignment() | Qt::TextSingleLine, l->text());

					QLinearGradient alphaGradient(QPoint(0,0), QPoint(tr.width(),0));
					alphaGradient.setColorAt(0.8, QColor(0,0,0,255));
					alphaGradient.setColorAt(1.0, QColor(0,0,0,0));
					p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
					p.fillRect(pixmap.rect(), alphaGradient);

					painter.drawPixmap(tr.topLeft(), pixmap);
				}
				else
					painter.drawText(tr, Qt::AlignLeft | Qt::AlignVCenter,
					                 l->text());

				return true;
			}

			return QObject::eventFilter(obj, event);
		}
コード例 #7
0
void AccountsListDelegate::updateItemWidgets(const QList<QWidget *> widgets, const QStyleOptionViewItem &option, const QPersistentModelIndex &index) const
{
    // draws:
    //                   AccountName
    // Checkbox | Icon |              | ConnectionIcon | ConnectionState
    //                   errorMessage

    if (!index.isValid()) {
        return;
    }

    Q_ASSERT(widgets.size() == 6);

    // Get the widgets
    QCheckBox* checkbox = qobject_cast<QCheckBox*>(widgets.at(0));
    ChangeIconButton* changeIconButton = qobject_cast<ChangeIconButton*>(widgets.at(1));
    QLabel *statusTextLabel = qobject_cast<QLabel*>(widgets.at(2));
    QLabel *statusIconLabel = qobject_cast<QLabel*>(widgets.at(3));
    EditDisplayNameButton *displayNameButton = qobject_cast<EditDisplayNameButton*>(widgets.at(4));
    QLabel *connectionErrorLabel = qobject_cast<QLabel*>(widgets.at(5));

    Q_ASSERT(checkbox);
    Q_ASSERT(changeIconButton);
    Q_ASSERT(statusTextLabel);
    Q_ASSERT(statusIconLabel);
    Q_ASSERT(displayNameButton);
    Q_ASSERT(connectionErrorLabel);


    bool isSelected(itemView()->selectionModel()->isSelected(index) && itemView()->hasFocus());
    bool isEnabled(index.data(KTp::AccountsListModel::EnabledRole).toBool());
    KIcon accountIcon(index.data(Qt::DecorationRole).value<QIcon>());
    KIcon statusIcon(index.data(KTp::AccountsListModel::ConnectionStateIconRole).value<QIcon>());
    QString statusText(index.data(KTp::AccountsListModel::ConnectionStateDisplayRole).toString());
    QString displayName(index.data(Qt::DisplayRole).toString());
    QString connectionError(index.data(KTp::AccountsListModel::ConnectionErrorMessageDisplayRole).toString());
    Tp::AccountPtr account(index.data(KTp::AccountsListModel::AccountRole).value<Tp::AccountPtr>());

    if (!account->isEnabled()) {
      connectionError = i18n("Click checkbox to enable");
    }

    QRect outerRect(0, 0, option.rect.width(), option.rect.height());
    QRect contentRect = outerRect.adjusted(m_hpadding,m_vpadding,-m_hpadding,-m_vpadding); //add some padding


    // checkbox
    if (isEnabled) {
        checkbox->setChecked(true);;
        checkbox->setToolTip(i18n("Disable account"));
    } else {
        checkbox->setChecked(false);
        checkbox->setToolTip(i18n("Enable account"));
    }

    int checkboxLeftMargin = contentRect.left();
    int checkboxTopMargin = (outerRect.height() - checkbox->height()) / 2;
    checkbox->move(checkboxLeftMargin, checkboxTopMargin);


    // changeIconButton
    changeIconButton->setIcon(accountIcon);
    changeIconButton->setAccount(account);
    // At the moment (KDE 4.8.1) decorationSize is not passed from KWidgetItemDelegate
    // through the QStyleOptionViewItem, therefore we leave default size unless
    // the user has a more recent version.
    if (option.decorationSize.width() > -1) {
        changeIconButton->setButtonIconSize(option.decorationSize.width());
    }

    int changeIconButtonLeftMargin = checkboxLeftMargin + checkbox->width();
    int changeIconButtonTopMargin = (outerRect.height() - changeIconButton->height()) / 2;
    changeIconButton->move(changeIconButtonLeftMargin, changeIconButtonTopMargin);


    // statusTextLabel
    QFont statusTextFont = option.font;
    QPalette statusTextLabelPalette = option.palette;
    if (isEnabled) {
        statusTextLabel->setEnabled(true);
        statusTextFont.setItalic(false);
    } else {
        statusTextLabel->setDisabled(true);
        statusTextFont.setItalic(true);
    }
    if (isSelected) {
        statusTextLabelPalette.setColor(QPalette::Text, statusTextLabelPalette.color(QPalette::Active, QPalette::HighlightedText));
    }
    statusTextLabel->setPalette(statusTextLabelPalette);
    statusTextLabel->setFont(statusTextFont);
    statusTextLabel->setText(statusText);
    statusTextLabel->setFixedSize(statusTextLabel->fontMetrics().boundingRect(statusText).width(),
                                  statusTextLabel->height());
    int statusTextLabelLeftMargin = contentRect.right() - statusTextLabel->width();
    int statusTextLabelTopMargin = (outerRect.height() - statusTextLabel->height()) / 2;
    statusTextLabel->move(statusTextLabelLeftMargin, statusTextLabelTopMargin);


    // statusIconLabel
    statusIconLabel->setPixmap(statusIcon.pixmap(KIconLoader::SizeSmall));
    statusIconLabel->setFixedSize(statusIconLabel->minimumSizeHint());
    int statusIconLabelLeftMargin = contentRect.right() - statusTextLabel->width() - statusIconLabel->width() - 6;
    int statusIconLabelTopMargin = (outerRect.height() - statusIconLabel->height()) / 2;
    statusIconLabel->move(statusIconLabelLeftMargin, statusIconLabelTopMargin);


    QRect innerRect = contentRect.adjusted(changeIconButton->geometry().right() - contentRect.left(),
                                           0,
                                           -statusTextLabel->width() - statusIconLabel->width() - 6,
                                           0); // rect containing account name and error message


    // displayNameButton
    QFont displayNameButtonFont = option.font;
    QPalette displayNameButtonPalette = option.palette;
    if (isEnabled) {
        displayNameButtonPalette.setColor(QPalette::WindowText, displayNameButtonPalette.color(QPalette::Active, QPalette::Text));
        displayNameButtonFont.setBold(true);
    } else {
        displayNameButtonFont.setItalic(true);
        // NOTE: Flat QPushButton use WindowText instead of ButtonText for button text color
        displayNameButtonPalette.setColor(QPalette::WindowText, displayNameButtonPalette.color(QPalette::Disabled, QPalette::Text));
    }
    if (isSelected) {
        // Account is selected
        displayNameButtonPalette.setColor(QPalette::WindowText, displayNameButtonPalette.color(QPalette::Active, QPalette::HighlightedText));
    }
    displayNameButton->setFont(displayNameButtonFont);
    displayNameButton->setPalette(displayNameButtonPalette);

    QString displayNameButtonText = displayNameButton->fontMetrics().elidedText(displayName,
                                                                                Qt::ElideRight,
                                                                                innerRect.width() - (m_hpadding*2));
    displayNameButton->setText(displayNameButtonText);
    displayNameButton->setFixedSize(displayNameButton->fontMetrics().boundingRect(displayNameButtonText).width() + (m_hpadding*2),
                                    displayNameButton->minimumSizeHint().height());
    displayNameButton->setAccount(account);

    int displayNameButtonLeftMargin = innerRect.left();
    int displayNameButtonTopMargin = innerRect.top();
    displayNameButton->move(displayNameButtonLeftMargin, displayNameButtonTopMargin);


    // connectionErrorLabel
    QFont connectionErrorLabelFont = option.font;
    QPalette connectionErrorLabelPalette = option.palette;
    if (isEnabled) {
        connectionErrorLabelPalette.setColor(QPalette::WindowText, connectionErrorLabelPalette.color(QPalette::Active, QPalette::Text));
    } else {
        connectionErrorLabelFont.setItalic(true);
        connectionErrorLabelPalette.setColor(QPalette::Text, connectionErrorLabelPalette.color(QPalette::Disabled, QPalette::Text));
    }
    if (isSelected) {
        // Account is selected
        connectionErrorLabelPalette.setColor(QPalette::Text, connectionErrorLabelPalette.color(QPalette::Active, QPalette::HighlightedText));
    }
    connectionErrorLabel->setFont(connectionErrorLabelFont);
    connectionErrorLabel->setPalette(connectionErrorLabelPalette);

    QString connectionErrorLabelText = connectionErrorLabel->fontMetrics().elidedText(connectionError,
                                                                                      Qt::ElideRight,
                                                                                      innerRect.width() - (m_hpadding*2));
    connectionErrorLabel->setText(connectionErrorLabelText);
    connectionErrorLabel->setFixedSize(connectionErrorLabel->fontMetrics().boundingRect(connectionErrorLabelText).width(),
                                       displayNameButton->height());

    int connectionErrorLabelLeftMargin = innerRect.left() + m_hpadding;
    int connectionErrorLabelTopMargin = contentRect.bottom() - displayNameButton->height();
    connectionErrorLabel->move(connectionErrorLabelLeftMargin, connectionErrorLabelTopMargin);
}
コード例 #8
0
MiniTargetWidget::MiniTargetWidget(Target *target, QWidget *parent) :
    QWidget(parent), m_target(target)
{
    Q_ASSERT(m_target);

    if (hasBuildConfiguration()) {
        m_buildComboBox = new QComboBox;
        m_buildComboBox->setProperty("alignarrow", true);
        m_buildComboBox->setProperty("hideborder", true);
        m_buildComboBox->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
        m_buildComboBox->setToolTip(tr("Select active build configuration"));
    } else {
        m_buildComboBox = 0;
    }
 
    m_runComboBox = new QComboBox;
    m_runComboBox ->setProperty("alignarrow", true);
    m_runComboBox ->setProperty("hideborder", true);
    m_runComboBox->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
    m_runComboBox->setToolTip(tr("Select active run configuration"));
    int fontSize = font().pointSize();
    setStyleSheet(QString::fromLatin1("QLabel { font-size: %2pt; color: white; } "
                                      "#target { font: bold %1pt;} "
                                      "#buildLabel{ font: bold; color: rgba(255, 255, 255, 160)} "
                                      "#runLabel { font: bold ; color: rgba(255, 255, 255, 160)} "
                                      ).arg(fontSize).arg(fontSize - 2));

    QGridLayout *gridLayout = new QGridLayout(this);

    m_targetName = new QLabel(m_target->displayName());
    m_targetName->setObjectName(QString::fromUtf8("target"));
    m_targetIcon = new QLabel();
    updateIcon();
    if (hasBuildConfiguration()) {
        Q_FOREACH(BuildConfiguration* bc, m_target->buildConfigurations())
                addBuildConfiguration(bc);

        connect(m_target, SIGNAL(addedBuildConfiguration(ProjectExplorer::BuildConfiguration*)),
                SLOT(addBuildConfiguration(ProjectExplorer::BuildConfiguration*)));
        connect(m_target, SIGNAL(removedBuildConfiguration(ProjectExplorer::BuildConfiguration*)),
                SLOT(removeBuildConfiguration(ProjectExplorer::BuildConfiguration*)));

        connect(m_target, SIGNAL(activeBuildConfigurationChanged(ProjectExplorer::BuildConfiguration*)),
                SLOT(setActiveBuildConfiguration()));
        connect(m_buildComboBox, SIGNAL(currentIndexChanged(int)), SLOT(setActiveBuildConfiguration(int)));
    }

    Q_FOREACH(RunConfiguration* rc, m_target->runConfigurations())
            addRunConfiguration(rc);

    connect(m_target, SIGNAL(addedRunConfiguration(ProjectExplorer::RunConfiguration*)),
            SLOT(addRunConfiguration(ProjectExplorer::RunConfiguration*)));
    connect(m_target, SIGNAL(removedRunConfiguration(ProjectExplorer::RunConfiguration*)),
            SLOT(removeRunConfiguration(ProjectExplorer::RunConfiguration*)));

    connect(m_runComboBox, SIGNAL(currentIndexChanged(int)), SLOT(setActiveRunConfiguration(int)));

    connect(m_target, SIGNAL(activeRunConfigurationChanged(ProjectExplorer::RunConfiguration*)),
            SLOT(setActiveRunConfiguration()));
    connect(m_target, SIGNAL(iconChanged()), this, SLOT(updateIcon()));

    QHBoxLayout *buildHelperLayout = 0;
    if (hasBuildConfiguration()) {
        buildHelperLayout= new QHBoxLayout;
        buildHelperLayout->setMargin(0);
        buildHelperLayout->setSpacing(0);
        buildHelperLayout->addWidget(m_buildComboBox);
    }

    QHBoxLayout *runHelperLayout = new QHBoxLayout;
    runHelperLayout->setMargin(0);
    runHelperLayout->setSpacing(0);
    runHelperLayout->addWidget(m_runComboBox);

    QFormLayout *formLayout = new QFormLayout;
    formLayout->setLabelAlignment(Qt::AlignRight);
    QLabel *lbl;
    int indent = 10;
    if (hasBuildConfiguration()) {
        lbl = new QLabel(tr("Build:"));
        lbl->setObjectName(QString::fromUtf8("buildLabel"));
        lbl->setMinimumWidth(lbl->fontMetrics().width(lbl->text()) + indent + 4);
        lbl->setIndent(indent);

        formLayout->addRow(lbl, buildHelperLayout);
    }
    lbl = new QLabel(tr("Run:"));
    lbl->setObjectName(QString::fromUtf8("runLabel"));
    lbl->setMinimumWidth(lbl->fontMetrics().width(lbl->text()) + indent + 4);
    lbl->setIndent(indent);
    formLayout->addRow(lbl, runHelperLayout);

    gridLayout->addWidget(m_targetName, 0, 0);
    gridLayout->addWidget(m_targetIcon, 0, 1, 2, 1, Qt::AlignTop|Qt::AlignHCenter);
    gridLayout->addLayout(formLayout, 1, 0);
}
コード例 #9
0
ファイル: main.cpp プロジェクト: jinghuaguo/Logger1
MainWindow::MainWindow(Logger * logger)
 : logger(logger),
   depthImage(640, 480, QImage::Format_RGB888),
   rgbImage(640, 480, QImage::Format_RGB888),
   recording(false),
   lastDrawn(-1)
{
    this->setMaximumSize(1280, 600);
    this->setMinimumSize(1280, 600);

    QVBoxLayout * wrapperLayout = new QVBoxLayout;

    QHBoxLayout * mainLayout = new QHBoxLayout;
    QHBoxLayout * fileLayout = new QHBoxLayout;
    QHBoxLayout * buttonLayout = new QHBoxLayout;

    wrapperLayout->addLayout(mainLayout);

    depthLabel = new QLabel(this);
    depthLabel->setPixmap(QPixmap::fromImage(depthImage));
    mainLayout->addWidget(depthLabel);

    imageLabel = new QLabel(this);
    imageLabel->setPixmap(QPixmap::fromImage(rgbImage));
    mainLayout->addWidget(imageLabel);

    wrapperLayout->addLayout(fileLayout);

    QLabel * logLabel = new QLabel("Log file: ", this);
    logLabel->setMaximumWidth(logLabel->fontMetrics().boundingRect(logLabel->text()).width());
    fileLayout->addWidget(logLabel);

    logFile = new QLabel(this);
    logFile->setTextInteractionFlags(Qt::TextSelectableByMouse);
    logFile->setStyleSheet("border: 1px solid grey");
    fileLayout->addWidget(logFile);

    browseButton = new QPushButton("Browse", this);
    browseButton->setMaximumWidth(browseButton->fontMetrics().boundingRect(browseButton->text()).width() + 10);
    connect(browseButton, SIGNAL(clicked()), this, SLOT(fileBrowse()));
    fileLayout->addWidget(browseButton);

    dateNameButton = new QPushButton("Date filename", this);
    dateNameButton->setMaximumWidth(dateNameButton->fontMetrics().boundingRect(dateNameButton->text()).width() + 10);
    connect(dateNameButton, SIGNAL(clicked()), this, SLOT(dateFilename()));
    fileLayout->addWidget(dateNameButton);

    wrapperLayout->addLayout(buttonLayout);

    startStop = new QPushButton("Record", this);
    connect(startStop, SIGNAL(clicked()), this, SLOT(recordToggle()));
    buttonLayout->addWidget(startStop);

    QPushButton * quitButton = new QPushButton("Quit", this);
    connect(quitButton, SIGNAL(clicked()), this, SLOT(quit()));
    buttonLayout->addWidget(quitButton);

    setLayout(wrapperLayout);

    startStop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    quitButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);

    QFont currentFont = startStop->font();
    currentFont.setPointSize(currentFont.pointSize() + 8);

    startStop->setFont(currentFont);
    quitButton->setFont(currentFont);

    painter = new QPainter(&depthImage);

    timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(timerCallback()));
    timer->start(15);

#ifdef unix
    char * homeDir = getenv("HOME");
    logFolder.append(homeDir);
    logFolder.append("/");
#else
    char * homeDrive = getenv("HOMEDRIVE");
    char * homeDir = getenv("HOMEPATH");
    logFolder.append(homeDrive);
    logFolder.append("\\");
    logFolder.append(homeDir);
    logFolder.append("\\");
#endif

    logFolder.append("Kinect_Logs");

    boost::filesystem::path p(logFolder.c_str());
    boost::filesystem::create_directory(p);

    logFile->setText(QString::fromStdString(getNextFilename()));
}
コード例 #10
0
ファイル: mainwindow.cpp プロジェクト: Fxrh/rekonq
void MainWindow::notifyMessage(const QString &msg, Rekonq::Notify status)
{
    if (this != QApplication::activeWindow())
    {
        return;
    }

    // deleting popus if empty msgs
    if (msg.isEmpty())
    {
        m_hidePopup->start(250);
        return;
    }

    m_hidePopup->stop();


    switch (status)
    {
    case Rekonq::Url:
        break;
    case Rekonq::Info:
        m_hidePopup->start(500);
        break;
    case Rekonq::Success:
        break;
    case Rekonq::Error:
        break;
    case Rekonq::Download:
        break;
    default:
        break;
    }

    int margin = 4;

    // setting the popup
    QLabel *label = new QLabel(msg);
    m_popup->setView(label);
    QSize labelSize(label->fontMetrics().width(msg) + 2*margin, label->fontMetrics().height() + 2*margin);
    if (labelSize.width() > width()) labelSize.setWidth(width());
    m_popup->setFixedSize(labelSize);
    m_popup->layout()->setAlignment(Qt::AlignTop);
    m_popup->layout()->setMargin(margin);

    // useful values
    WebTab *tab = m_view->currentWebTab();

    // fix crash on window close
    if (!tab)
        return;

    // fix crash on window close
    if (!tab->page())
        return;

    bool scrollbarIsVisible = tab->page()->currentFrame()->scrollBarMaximum(Qt::Horizontal);
    int scrollbarSize = 0;
    if (scrollbarIsVisible)
    {
        //TODO: detect QStyle size
        scrollbarSize = 17;
    }

    QPoint webViewOrigin = tab->view()->mapToGlobal(QPoint(0, 0));
    int bottomLeftY = webViewOrigin.y() + tab->page()->viewportSize().height() - labelSize.height() - scrollbarSize;

    // setting popup in bottom-left position
    int x = geometry().x();
    int y = bottomLeftY;

    QPoint mousePos = tab->mapToGlobal(tab->view()->mousePos());
    if (QRect(webViewOrigin.x() , bottomLeftY , labelSize.width() , labelSize.height()).contains(mousePos))
    {
        // setting popup above the mouse
        y = bottomLeftY - labelSize.height();
    }

    m_popup->show(QPoint(x, y));
}
コード例 #11
0
QWidget* CanvasContainer::scaleSlider()
{
    if (!scaleSliderWidget)
    {
        scaleSliderWidget = new QWidget(this);
        QHBoxLayout *layout = new QHBoxLayout(scaleSliderWidget);
        QSlider *slider = new QSlider(Qt::Horizontal, scaleSliderWidget);
        QLabel *label = new QLabel("100%", scaleSliderWidget);
        label->setFixedWidth(label->fontMetrics().width("100.%"));
        label->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
        //label->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); //not working?

        scaleSliderWidget->setLayout(layout);
        layout->addWidget(slider);
        layout->addWidget(label);
        layout->setContentsMargins(0, 0, 0, 0);

        qreal internalFactor = -100 * qLn(MIN_SCALE_FACTOR) / MIN_SCALE_FACTOR / qLn(2);
        slider->setRange(-qCeil(MIN_SCALE_FACTOR * internalFactor),
                         qCeil(MAX_SCALE_FACTOR - 1) * 100);
        slider->setPageStep(100);
        slider->setTickPosition(QSlider::TicksBelow);

        auto setScaleOrigin = [=]()
        {
            if (proxy)
            {
                QPointF position = proxy->mapFromScene(mapToScene(viewport()->rect().center()));
                if (proxy->rect().contains(position))
                    proxy->setTransformOriginPoint(position);
            }
        };

        auto calculateScale = [=](int sliderValue)
        {
            if (sliderValue >= 0)
            {
                qreal newScale = 1.0 + 0.01 * sliderValue;
                if (!qFuzzyCompare(newScale, currentScaleFactor()))
                {
                    setScaleOrigin();
                    setScaleFactor(1.0 + 0.01 * sliderValue);
                    label->setText(QString("%1%").arg(100 + sliderValue));
                }
              }
            else
            {
                qreal newScale = qPow(MIN_SCALE_FACTOR, -sliderValue / internalFactor / MIN_SCALE_FACTOR);
                if (!qFuzzyCompare(newScale, currentScaleFactor()))
                {
                    setScaleOrigin();
                    setScaleFactor(newScale);
                    label->setText(QString("%1%").arg(newScale * 100, 0, 'f', 1));
                }
            }
        };
        auto calculateValue = [=](qreal scaleFactor)
        {
            slider->blockSignals(true);
            if (scaleFactor >= 1.0)
            {
                int newValue = 100 * scaleFactor - 100;
                if (newValue != slider->value())
                {
                    slider->setValue(newValue);
                    label->setText(QString("%1%").arg(qFloor(100 * scaleFactor)));
                }
            }
            else
            {
                int newValue = -internalFactor * MIN_SCALE_FACTOR / qLn(MIN_SCALE_FACTOR) * qLn(scaleFactor);
                if (newValue != slider->value())
                {
                    slider->setValue(newValue);
                    label->setText(QString("%1%").arg(100 * scaleFactor, 0, 'f', 1));
                }
            }
            slider->blockSignals(false);
        };

        connect(slider, &QSlider::valueChanged, calculateScale);
        connect(this, &CanvasContainer::scaled, calculateValue);
    }
    return scaleSliderWidget;
}
コード例 #12
0
ファイル: main.cpp プロジェクト: caomw/Logger2
MainWindow::MainWindow(int width, int height, int fps, bool tcp)
 : logger(0),
   depthImage(width, height, QImage::Format_RGB888),
   rgbImage(width, height, QImage::Format_RGB888),
   recording(false),
   lastDrawn(-1),
   width(width),
   height(height),
   fps(fps),
   tcp(tcp), 
   comms(tcp ? new Communicator : 0)
{
    this->setMaximumSize(width * 2, height + 160);
    this->setMinimumSize(width * 2, height + 160);

    QVBoxLayout * wrapperLayout = new QVBoxLayout;

    QHBoxLayout * mainLayout = new QHBoxLayout;
    QHBoxLayout * fileLayout = new QHBoxLayout;
    QHBoxLayout * optionLayout = new QHBoxLayout;
    QHBoxLayout * buttonLayout = new QHBoxLayout;

    wrapperLayout->addLayout(mainLayout);

    depthLabel = new QLabel(this);
    depthLabel->setPixmap(QPixmap::fromImage(depthImage));
    mainLayout->addWidget(depthLabel);

    imageLabel = new QLabel(this);
    imageLabel->setPixmap(QPixmap::fromImage(rgbImage));
    mainLayout->addWidget(imageLabel);

    wrapperLayout->addLayout(fileLayout);
    wrapperLayout->addLayout(optionLayout);

    QLabel * logLabel = new QLabel("Log file: ", this);
    logLabel->setMaximumWidth(logLabel->fontMetrics().boundingRect(logLabel->text()).width());
    fileLayout->addWidget(logLabel);

    logFile = new QLabel(this);
    logFile->setTextInteractionFlags(Qt::TextSelectableByMouse);
    logFile->setStyleSheet("border: 1px solid grey");
    fileLayout->addWidget(logFile);

#ifdef __APPLE__
    int cushion = 25;
#else
    int cushion = 10;
#endif

    browseButton = new QPushButton("Browse", this);
    browseButton->setMaximumWidth(browseButton->fontMetrics().boundingRect(browseButton->text()).width() + cushion);
    connect(browseButton, SIGNAL(clicked()), this, SLOT(fileBrowse()));
    fileLayout->addWidget(browseButton);

    dateNameButton = new QPushButton("Date filename", this);
    dateNameButton->setMaximumWidth(dateNameButton->fontMetrics().boundingRect(dateNameButton->text()).width() + cushion);
    connect(dateNameButton, SIGNAL(clicked()), this, SLOT(dateFilename()));
    fileLayout->addWidget(dateNameButton);

    autoExposure = new QCheckBox("Auto Exposure");
    autoExposure->setChecked(false);

    autoWhiteBalance = new QCheckBox("Auto White Balance");
    autoWhiteBalance->setChecked(false);

    compressed = new QCheckBox("Compressed");
    compressed->setChecked(true);

    memoryRecord = new QCheckBox("Record to RAM");
    memoryRecord->setChecked(false);

    memoryStatus = new QLabel("");

    connect(autoExposure, SIGNAL(stateChanged(int)), this, SLOT(setExposure()));
    connect(autoWhiteBalance, SIGNAL(stateChanged(int)), this, SLOT(setWhiteBalance()));
    connect(compressed, SIGNAL(released()), this, SLOT(setCompressed()));
    connect(memoryRecord, SIGNAL(stateChanged(int)), this, SLOT(setMemoryRecord()));

    optionLayout->addWidget(autoExposure);
    optionLayout->addWidget(autoWhiteBalance);
    optionLayout->addWidget(compressed);
    optionLayout->addWidget(memoryRecord);
    optionLayout->addWidget(memoryStatus);

    wrapperLayout->addLayout(buttonLayout);

    startStop = new QPushButton(tcp ? "Stream && Record" : "Record", this);
    connect(startStop, SIGNAL(clicked()), this, SLOT(recordToggle()));
    buttonLayout->addWidget(startStop);

    QPushButton * quitButton = new QPushButton("Quit", this);
    connect(quitButton, SIGNAL(clicked()), this, SLOT(quit()));
    buttonLayout->addWidget(quitButton);

    setLayout(wrapperLayout);

    startStop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    quitButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);

    QFont currentFont = startStop->font();
    currentFont.setPointSize(currentFont.pointSize() + 8);

    startStop->setFont(currentFont);
    quitButton->setFont(currentFont);

    painter = new QPainter(&depthImage);

    painter->setPen(Qt::green);
    painter->setFont(QFont("Arial", 30));
    painter->drawText(10, 50, "Attempting to start OpenNI2...");
    depthLabel->setPixmap(QPixmap::fromImage(depthImage));

#ifndef OS_WINDOWS
    char * homeDir = getenv("HOME");
    logFolder.append(homeDir);
    logFolder.append("/");
#else
    char * homeDrive = getenv("HOMEDRIVE");
    char * homeDir = getenv("HOMEPATH");
    logFolder.append(homeDrive);
    logFolder.append("\\");
    logFolder.append(homeDir);
    logFolder.append("\\");
#endif

    logFolder.append("Kinect_Logs");

    boost::filesystem::path p(logFolder.c_str());
    boost::filesystem::create_directory(p);

    logFile->setText(QString::fromStdString(getNextFilename()));

    timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(timerCallback()));
    timer->start(15);
}
コード例 #13
0
ファイル: mapindicator.cpp プロジェクト: mdovgialo/cockpit3
void MapIndicator::update_ind(Gamestate* actual)
{

    QJsonArray mapObj = actual->mapObj.array();
    int player = -1;
    bool playerTank = 0;

    float mapW = actual->mapInfo.object()["map_max"].toArray()[0].toDouble() - actual->mapInfo.object()["map_min"].toArray()[0].toDouble();
    float mapH = actual->mapInfo.object()["map_max"].toArray()[1].toDouble() - actual->mapInfo.object()["map_min"].toArray()[1].toDouble();

    for (int i =0; i<mapObj.size(); ++i)
    {
        if(mapObj[i].toObject()["icon"].toString() == QString("Player"))
        {
            player = i;
            if(mapObj[i].toObject()["type"].toString()==QString("ground_model"))
            {
                playerTank = 1;
            }
            break;
        }

    }



    if(mapObj.isEmpty() or player==-1 or (!playerTank and overlay))
    {
        mapValid = false;
        this->hide();

    }
    else if ((!overlay) or playerTank)
    {
        if(mapValid==false)
        {
            if(this->overlay)
            {
                QPixmap n(text.size());
                n.fill(QColor(0,0,0,0));
                text.setPixmap(n);
                cout << "Setting empty pixmap"<<endl;
            }
            else
            {

                QUrl url(dynamic_cast<InstrumentPanel*>(this->parent())->settings["url"].toString()+QString("/map.img"));
                QNetworkRequest request(url);
                cout << "Downloading image " << request.url().toString().toStdString()<<endl;
                manager->get(request);
            }


        }
        //cout << "Painting map Object!"<<endl;
        double playerX = mapObj[player].toObject()["x"].toDouble();
        double playerY = mapObj[player].toObject()["y"].toDouble();

        qDeleteAll(mapObjects->findChildren<QLabel*>());

        for (int i =0; i<mapObj.size(); ++i)
        {

           QLabel* obj; ;

           double x = mapObj[i].toObject()["x"].toDouble();
           double y = mapObj[i].toObject()["y"].toDouble();
           int mapX = x*this->size().width();
           int mapY =  y*this->size().height();
           int dist = sqrt((x-playerX)*mapW*(x-playerX)*mapW+(y-playerY)*mapH*(y-playerY)*mapW);
           //cout << dist<<endl;
            QWidget* obscure =  mapObjects->childAt(mapX, mapY);
           int obscureX = text.fontMetrics().size(Qt::TextSingleLine, "00").width();
           int obscureY = text.fontMetrics().size(Qt::TextSingleLine, "00").height();
           QWidget* obscure2 =  mapObjects->childAt(mapX+obscureX, mapY+obscureY);
           QWidget* obscure3 =  mapObjects->childAt(mapX-obscureX, mapY-obscureY);
           QWidget* obscure4 =  mapObjects->childAt(mapX-obscureX, mapY+obscureY);
           QWidget* obscure5 =  mapObjects->childAt(mapX+obscureX, mapY-obscureY);

           if(!(obscure or obscure2 or obscure3 or obscure4 or obscure5))
           {
               obj = new QLabel(mapObjects);
               obj->setText( QString::number(dist));
               if(this->size().width()>400  and params["scaling_text"].toBool())
               {
                   QFont ff = obj->font();
                   ff.setPixelSize(this->size().width()/26);
                   obj->setFont(ff);
               }

               obj->move(mapX, mapY);
               obj->show();


           }

           if(!overlay)
           {
               obj = new QLabel(mapObjects);
               if( mapObj[i].toObject()["icon_bg"].toString().indexOf("Target")>-1)
               {
                   obj->setStyleSheet(QString("QLabel { color: gold}"));
               }
               else
               {
                obj->setStyleSheet(QString("QLabel { color: ") + mapObj[i].toObject()["color"].toString()+QString("}"));
               }

               if(mapObj[i].toObject()["type"].toString() == QString("aircraft"))
               {
                    obj->setText("^");
               }
               else if(mapObj[i].toObject()["type"].toString() == QString("ground_model"))
               {
                    obj->setText("=");
               }

               if(mapObj[i].toObject()["icon"].toString() == QString("Player"))
               {
                     obj->setText("o");
                     obj->setStyleSheet(QString("QLabel { font: bold; color: green}"));
               }
               if(this->size().width()>400 and params["scaling_text"].toBool())
               {
                   QFont ff = obj->font();
                   ff.setPixelSize(this->size().width()/26);
                   obj->setFont(ff);
               }




               //obj->setStyleSheet(QString("QLabel { color: ") + mapObj[i].toObject()["color"].toString()+QString("}"));

               obj->move(mapX-obj->fontMetrics().size(Qt::TextSingleLine, "0").height()/2, mapY-obj->fontMetrics().size(Qt::TextSingleLine, "0").height()/2);
               obj->show();
           }

           /*if( mapObj[i].toObject()["icon_bg"].toString().indexOf("Target")>-1)
           {
               obj = new QLabel(mapObjects);
               obj->setText( QString("Target distance: ")+QString::number(dist));
              // obj->setStyleSheet(QString("QLabel { color: ") + mapObj[i].toObject()["color"].toString()+QString("}"));

               obj->move(0,0);
               obj->show();

               obj->setStyleSheet(QString("QLabel { font: bold 15px; color: red}"));
               obj->resize(obj->sizeHint());
           }*/

        }
        mapObjects->raise();
        this->show();
        mapValid = true;

    }
}