Esempio n. 1
0
void QgsAttributeEditor::selectDate()
{
  QPushButton *pb = qobject_cast<QPushButton *>( sender() );
  if ( !pb )
    return;

  QWidget *hbox = qobject_cast<QWidget *>( pb->parent() );
  if ( !hbox )
    return;

  QLineEdit *le = hbox->findChild<QLineEdit *>();
  if ( !le )
    return;

  QDialog *dlg = new QDialog();
  dlg->setWindowTitle( tr( "Select a date" ) );
  QVBoxLayout *vl = new QVBoxLayout( dlg );

  QCalendarWidget *cw = new QCalendarWidget( dlg );
  cw->setSelectedDate( QDate::fromString( le->text(), Qt::ISODate ) );
  vl->addWidget( cw );

  QDialogButtonBox *buttonBox = new QDialogButtonBox( dlg );
  buttonBox->addButton( QDialogButtonBox::Ok );
  buttonBox->addButton( QDialogButtonBox::Cancel );
  vl->addWidget( buttonBox );

  connect( buttonBox, SIGNAL( accepted() ), dlg, SLOT( accept() ) );
  connect( buttonBox, SIGNAL( rejected() ), dlg, SLOT( reject() ) );

  if ( dlg->exec() == QDialog::Accepted )
  {
    le->setText( cw->selectedDate().toString( Qt::ISODate ) );
  }
}
Esempio n. 2
0
void LxQtClock::activated(ActivationReason reason)
{
    if (reason != ILxQtPanelPlugin::Trigger)
        return;

    if (!mCalendarDialog)
    {
        mCalendarDialog = new QDialog(mContent);
        //mCalendarDialog->setAttribute(Qt::WA_DeleteOnClose, true);
        mCalendarDialog->setWindowFlags(Qt::FramelessWindowHint | Qt::Dialog | Qt::X11BypassWindowManagerHint);
        mCalendarDialog->setLayout(new QHBoxLayout(mCalendarDialog));
        mCalendarDialog->layout()->setMargin(1);

        QCalendarWidget* cal = new QCalendarWidget(mCalendarDialog);
        cal->setFirstDayOfWeek(mFirstDayOfWeek);
        mCalendarDialog->layout()->addWidget(cal);
        mCalendarDialog->adjustSize();
        QRect pos = calculatePopupWindowPos(mCalendarDialog->size());
        mCalendarDialog->move(pos.topLeft());
        mCalendarDialog->show();
    }
    else
    {
        delete mCalendarDialog;
        mCalendarDialog = 0;
    }
}
Esempio n. 3
0
QGraphicsItem *WidgetDemo::item() {
  QCalendarWidget *date = new QCalendarWidget(0);
  date->setWindowOpacity(0.2);
  date->resize(300, 200);
  date->move(20, 20);

  return new PlexyDesk::WidgetItem(QRectF(0, 0, 340, 240), date);
}
Esempio n. 4
0
void  MultiDelegate::setupCalenderWidget( QDateTimeEdit* editor)  const
{
    editor->setCalendarPopup(true);
    QCalendarWidget*  calendar = editor->calendarWidget();
    if (calendar) {
        calendar->setFirstDayOfWeek(Qt::Monday);
        calendar->setVerticalHeaderFormat( QCalendarWidget::ISOWeekNumbers);
    }
}
Esempio n. 5
0
int main(int argc, char *argv[])
{
  QApplication app(argc, argv);
  QCalendarWidget *label = new QCalendarWidget();
  label->setObjectName(QString::fromUtf8("label"));
  label->setGeometry(QRect(100, 100, 200, 100));
 // label->setText("Hello World");
  label->show();
  return app.exec();
}
Esempio n. 6
0
void CmdTestRedirectPaint::activated(int iMsg)
{
    QCalendarWidget* cal = new QCalendarWidget();
    QLabel* label = new QLabel();
    QPainter::setRedirected(cal,label);
    cal->setWindowTitle(QString::fromAscii("QCalendarWidget"));
    cal->show();
    label->show();
    label->setWindowTitle(QString::fromAscii("QLabel"));
}
Esempio n. 7
0
void LXQtWorldClock::activated(ActivationReason reason)
{
    switch (reason)
    {
    case ILXQtPanelPlugin::Trigger:
    case ILXQtPanelPlugin::MiddleClick:
        break;

    default:
        return;
    }

    if (!mPopup)
    {
        mPopup = new LXQtWorldClockPopup(mContent);
        connect(mPopup, SIGNAL(deactivated()), SLOT(deletePopup()));

        if (reason == ILXQtPanelPlugin::Trigger)
        {
            mPopup->setObjectName(QLatin1String("WorldClockCalendar"));

            mPopup->layout()->setContentsMargins(0, 0, 0, 0);
            QCalendarWidget *calendarWidget = new QCalendarWidget(mPopup);
            mPopup->layout()->addWidget(calendarWidget);

            QString timeZoneName = mActiveTimeZone;
            if (timeZoneName == QLatin1String("local"))
                timeZoneName = QString::fromLatin1(QTimeZone::systemTimeZoneId());

            QTimeZone timeZone(timeZoneName.toLatin1());
            calendarWidget->setFirstDayOfWeek(QLocale(QLocale::AnyLanguage, timeZone.country()).firstDayOfWeek());
            calendarWidget->setSelectedDate(QDateTime::currentDateTime().toTimeZone(timeZone).date());
        }
        else
        {
            mPopup->setObjectName(QLatin1String("WorldClockPopup"));

            mPopupContent = new QLabel(mPopup);
            mPopup->layout()->addWidget(mPopupContent);
            mPopupContent->setAlignment(mContent->alignment());

            updatePopupContent();
        }

        mPopup->adjustSize();
        mPopup->setGeometry(calculatePopupWindowPos(mPopup->size()));

        willShowWindow(mPopup);
        mPopup->show();
    }
    else
    {
        deletePopup();
    }
}
void tst_QCalendarWidget::setTextFormat()
{
    QCalendarWidget calendar;
    QTextCharFormat format;
    format.setFontItalic(true);
    format.setForeground(Qt::green);

    const QDate date(1984, 10, 20);
    calendar.setDateTextFormat(date, format);
    QCOMPARE(calendar.dateTextFormat(date), format);
}
Esempio n. 9
0
void CmdTestGrabWidget::activated(int iMsg)
{
    QCalendarWidget* c = new QCalendarWidget();
    c->hide();
    QPixmap p = QPixmap::grabWidget(c, c->rect());
    QLabel* label = new QLabel();
    label->resize(c->size());
    label->setPixmap(p);
    label->show();
    delete c;
}
Esempio n. 10
0
QDate QtopiaInputDialog::getDate(QWidget *parent, const QString &title, const QString &label, const QDate &date,
                                 const QDate &minDate, const QDate &maxDate, bool *ok)
{
#ifdef CALENDAR_FOR_DATE
    QCalendarWidget *cal = new QCalendarWidget();
    cal->setSelectedDate(date);
    cal->setMinimumDate(minDate);
    cal->setMaximumDate(maxDate);
    cal->setVerticalHeaderFormat(QCalendarWidget::NoVerticalHeader);
    QTextCharFormat headerFormat = cal->headerTextFormat();
    headerFormat.setBackground(QApplication::palette().window());
    headerFormat.setForeground(QApplication::palette().windowText());
    cal->setHeaderTextFormat(headerFormat);
    QWidget *navBar = cal->findChild<QWidget*>("qt_calendar_navigationbar");
    if (navBar)
        navBar->setBackgroundRole(QPalette::Window);

    QtopiaInputDialog dlg(parent, title, label, cal);
    bool accepted = (QtopiaApplication::execDialog(&dlg) == QDialog::Accepted);
    if (ok)
        *ok = accepted;
    return cal->selectedDate();
#else
    QDateEdit *de = new QDateEdit(date);
    de->setMinimumDate(minDate);
    de->setMaximumDate(maxDate);

    QtopiaInputDialog dlg(parent, title, label, de);
    bool accepted = (QtopiaApplication::execDialog(&dlg) == QDialog::Accepted);
    if (ok)
        *ok = accepted;
    return de->date();
#endif
}
Esempio n. 11
0
void BlDateSearch::s_searchFecha()
{
    BL_FUNC_DEBUG

    QDialog *diag = new QDialog ( 0 );
    diag->setModal ( true );
    QCalendarWidget *calend = new QCalendarWidget ( diag );
    /// Se pone el 1er dia del calendario a lunes.
    calend->setFirstDayOfWeek ( Qt::Monday );

    /// Evitar fechas demasiado antiguas
    calend->setMinimumDate( QDate ( 1900, 1, 1 ) );

    /// Si el campo estaba vac&iacute;o, seleccionar una fecha imposible, pero mostrar el mes actual
    if ( m_textoFecha->text().isEmpty() ) {
        calend->setSelectedDate ( calend->minimumDate() );
        calend->setCurrentPage ( QDate::currentDate().year(), QDate::currentDate().month() );
    }

    /// Si ya hay una fecha en el campo, abrir el calendario con ese d&iacute;a seleccionado inicialmente
    else {
        calend->setSelectedDate ( blNormalizeDate ( m_textoFecha->text() ) );
    }

    connect ( calend, SIGNAL ( activated ( const QDate & ) ), diag, SLOT ( accept() ) );

    /// Creamos un layout donde estara el contenido de la ventana y la ajustamos al QDialog
    /// para que sea redimensionable y aparezca el titulo de la ventana.
    QHBoxLayout *layout = new QHBoxLayout;
    layout->addWidget ( calend );
    layout->setMargin ( 0 );
    layout->setSpacing ( 0 );
    diag->setLayout ( layout );
    diag->setWindowTitle ( _ ( "Seleccione fecha" ) );
    diag->exec();

    /// Si la fecha es imposible, significa que el usuario no ha seleccionado una fecha
    /// y su campo debe quedarse como estaba: vac&iacute;o
    if ( calend->selectedDate() != QDate ( 1900, 1, 1 ) ) {
        m_textoFecha->setText ( calend->selectedDate().toString ( "dd/MM/yyyy" ) );
    }

    /// Liberamos la memoria
    delete layout;
    delete calend;
    delete diag;

    emit ( valueChanged ( m_textoFecha->text() ) );
    emit ( editingFinished () );

    
}
Esempio n. 12
0
void tst_QCalendarWidget::setWeekdayFormat()
{
    QCalendarWidget calendar;

    QTextCharFormat format;
    format.setFontItalic(true);
    format.setForeground(Qt::green);

    calendar.setWeekdayTextFormat(Qt::Wednesday, format);

    // check the format of the a given month
    for (int i = 1; i <= 31; ++i) {
        const QDate date(1984, 10, i);
        const Qt::DayOfWeek dayOfWeek = static_cast<Qt::DayOfWeek>(date.dayOfWeek());
        if (dayOfWeek == Qt::Wednesday)
            QCOMPARE(calendar.weekdayTextFormat(dayOfWeek), format);
        else
            QVERIFY(calendar.weekdayTextFormat(dayOfWeek) != format);
    }
}
Esempio n. 13
0
void Overview::UpdateCalendarDay(QDateEdit *dateedit, QDate date)
{
    QCalendarWidget *calendar = dateedit->calendarWidget();
    QTextCharFormat bold;
    QTextCharFormat cpapcol;
    QTextCharFormat normal;
    QTextCharFormat oxiday;
    bold.setFontWeight(QFont::Bold);
    cpapcol.setForeground(QBrush(Qt::blue, Qt::SolidPattern));
    cpapcol.setFontWeight(QFont::Bold);
    oxiday.setForeground(QBrush(Qt::red, Qt::SolidPattern));
    oxiday.setFontWeight(QFont::Bold);
    bool hascpap = p_profile->FindDay(date, MT_CPAP) != nullptr;
    bool hasoxi = p_profile->FindDay(date, MT_OXIMETER) != nullptr;
    //bool hasjournal=p_profile->GetDay(date,MT_JOURNAL)!=nullptr;

    if (hascpap) {
        if (hasoxi) {
            calendar->setDateTextFormat(date, oxiday);
        } else {
            calendar->setDateTextFormat(date, cpapcol);
        }
    } else if (p_profile->GetDay(date)) {
        calendar->setDateTextFormat(date, bold);
    } else {
        calendar->setDateTextFormat(date, normal);
    }

    calendar->setHorizontalHeaderFormat(QCalendarWidget::ShortDayNames);
}
Esempio n. 14
0
void tst_QCalendarWidget::buttonClickCheck()
{
    QCalendarWidget object;
    QSize size = object.sizeHint();
    object.setGeometry(0,0,size.width(), size.height());
    object.show();
    object.activateWindow();
    QVERIFY(QTest::qWaitForWindowActive(&object));

    QDate selectedDate(2005, 1, 1);
    //click on the month buttons
    int month = object.monthShown();
    QToolButton *button = object.findChild<QToolButton *>("qt_calendar_prevmonth");
    QTest::mouseClick(button, Qt::LeftButton);
    QCOMPARE(month > 1 ? month-1 : 12, object.monthShown());
    button = object.findChild<QToolButton *>("qt_calendar_nextmonth");
    QTest::mouseClick(button, Qt::LeftButton);
    QCOMPARE(month, object.monthShown());

    button = object.findChild<QToolButton *>("qt_calendar_yearbutton");
    QTest::mouseClick(button, Qt::LeftButton, Qt::NoModifier, button->rect().center(), 2);
    QVERIFY(!button->isVisible());
    QSpinBox *spinbox = object.findChild<QSpinBox *>("qt_calendar_yearedit");
    QTest::qWait(500);
    QTest::keyClick(spinbox, '2');
    QTest::keyClick(spinbox, '0');
    QTest::keyClick(spinbox, '0');
    QTest::keyClick(spinbox, '6');
    QTest::qWait(500);
    QWidget *widget = object.findChild<QWidget *>("qt_calendar_calendarview");
    QTest::mouseMove(widget);
    QTest::mouseClick(widget, Qt::LeftButton);
    QCOMPARE(2006, object.yearShown());
    object.setSelectedDate(selectedDate);
    object.showSelectedDate();
    QTest::keyClick(widget, Qt::Key_Down);
    QVERIFY(selectedDate != object.selectedDate());

    object.setDateRange(QDate(2006,1,1), QDate(2006,2,28));
    object.setSelectedDate(QDate(2006,1,1));
    object.showSelectedDate();
    button = object.findChild<QToolButton *>("qt_calendar_prevmonth");
    QTest::mouseClick(button, Qt::LeftButton);
    QCOMPARE(1, object.monthShown());

    button = object.findChild<QToolButton *>("qt_calendar_nextmonth");
    QTest::mouseClick(button, Qt::LeftButton);
    QCOMPARE(2, object.monthShown());
    QTest::mouseClick(button, Qt::LeftButton);
    QCOMPARE(2, object.monthShown());

}
Esempio n. 15
0
bool QgsAttributeEditor::retrieveValue( QWidget *widget, QgsVectorLayer *vl, int idx, QVariant &value )
{
  if ( !widget )
    return false;

  const QgsField &theField = vl->pendingFields()[idx];
  QgsVectorLayer::EditType editType = vl->editType( idx );
  bool modified = false;
  QString text;

  QSettings settings;
  QString nullValue = settings.value( "qgis/nullValue", "NULL" ).toString();

  QLineEdit *le = qobject_cast<QLineEdit *>( widget );
  if ( le )
  {
    text = le->text();
    modified = le->isModified();
    if ( text == nullValue )
    {
      text = QString::null;
    }
  }

  QTextEdit *te = qobject_cast<QTextEdit *>( widget );
  if ( te )
  {
    text = te->toHtml();
    modified = te->document()->isModified();
    if ( text == nullValue )
    {
      text = QString::null;
    }
  }

  QPlainTextEdit *pte = qobject_cast<QPlainTextEdit *>( widget );
  if ( pte )
  {
    text = pte->toPlainText();
    modified = pte->document()->isModified();
    if ( text == nullValue )
    {
      text = QString::null;
    }
  }

  QComboBox *cb = qobject_cast<QComboBox *>( widget );
  if ( cb )
  {
    if ( editType == QgsVectorLayer::UniqueValues ||
         editType == QgsVectorLayer::ValueMap ||
         editType == QgsVectorLayer::Classification ||
         editType == QgsVectorLayer::ValueRelation )
    {
      text = cb->itemData( cb->currentIndex() ).toString();
      if ( text == nullValue )
      {
        text = QString::null;
      }
    }
    else
    {
      text = cb->currentText();
    }
    modified = true;
  }

  QListWidget *lw = qobject_cast<QListWidget *>( widget );
  if ( lw )
  {
    if ( editType == QgsVectorLayer::ValueRelation )
    {
      text = '{';
      for ( int i = 0, n = 0; i < lw->count(); i++ )
      {
        if ( lw->item( i )->checkState() == Qt::Checked )
        {
          if ( n > 0 )
          {
            text.append( ',' );
          }
          text.append( lw->item( i )->data( Qt::UserRole ).toString() );
          n++;
        }
      }
      text.append( '}' );
    }
    else
    {
      text = QString::null;
    }
    modified = true;
  }

  QSpinBox *sb = qobject_cast<QSpinBox *>( widget );
  if ( sb )
  {
    text = QString::number( sb->value() );
  }

  QAbstractSlider *slider = qobject_cast<QAbstractSlider *>( widget );
  if ( slider )
  {
    text = QString::number( slider->value() );
  }

  QDoubleSpinBox *dsb = qobject_cast<QDoubleSpinBox *>( widget );
  if ( dsb )
  {
    text = QString::number( dsb->value() );
  }

  QCheckBox *ckb = qobject_cast<QCheckBox *>( widget );
  if ( ckb )
  {
    QPair<QString, QString> states = vl->checkedState( idx );
    text = ckb->isChecked() ? states.first : states.second;
  }

  QCalendarWidget *cw = qobject_cast<QCalendarWidget *>( widget );
  if ( cw )
  {
    text = cw->selectedDate().toString();
  }

  le = widget->findChild<QLineEdit *>();
  if ( le )
  {
    text = le->text();
  }

  switch ( theField.type() )
  {
    case QVariant::Int:
    {
      bool ok;
      int myIntValue = text.toInt( &ok );
      if ( ok && !text.isEmpty() )
      {
        value = QVariant( myIntValue );
        modified = true;
      }
      else if ( modified )
      {
        value = QVariant();
      }
    }
    break;
    case QVariant::LongLong:
    {
      bool ok;
      qlonglong myLongValue = text.toLong( &ok );
      if ( ok && !text.isEmpty() )
      {
        value = QVariant( myLongValue );
        modified = true;
      }
      else if ( modified )
      {
        value = QVariant();
      }
    }
    case QVariant::Double:
    {
      bool ok;
      double myDblValue = text.toDouble( &ok );
      if ( ok && !text.isEmpty() )
      {
        value = QVariant( myDblValue );
        modified = true;
      }
      else if ( modified )
      {
        value = QVariant();
      }
    }
    break;
    case QVariant::Date:
    {
      QDate myDateValue = QDate::fromString( text, Qt::ISODate );
      if ( myDateValue.isValid() && !text.isEmpty() )
      {
        value = myDateValue;
        modified = true;
      }
      else if ( modified )
      {
        value = QVariant();
      }
    }
    break;
    default: //string
      modified = true;
      value = QVariant( text );
      break;
  }

  return modified;
}
Esempio n. 16
0
bool QgsAttributeEditor::setValue( QWidget *editor, QgsVectorLayer *vl, int idx, const QVariant &value )
{
    if ( !editor )
        return false;

    QgsVectorLayer::EditType editType = vl->editType( idx );
    const QgsField &field = vl->pendingFields()[idx];
    QVariant::Type myFieldType = field.type();

    QSettings settings;
    QString nullValue = settings.value( "qgis/nullValue", "NULL" ).toString();

    switch ( editType )
    {
    case QgsVectorLayer::Classification:
    case QgsVectorLayer::UniqueValues:
    case QgsVectorLayer::Enumeration:
    case QgsVectorLayer::ValueMap:
    case QgsVectorLayer::ValueRelation:
    {
        QVariant v = value;
        QComboBox *cb = qobject_cast<QComboBox *>( editor );
        if ( !cb )
            return false;

        if ( v.isNull() )
        {
            v = nullValue;
        }

        int idx = cb->findData( v );
        if ( idx < 0 )
            return false;

        cb->setCurrentIndex( idx );
    }
    break;

    case QgsVectorLayer::DialRange:
    case QgsVectorLayer::SliderRange:
    case QgsVectorLayer::EditRange:
    {
        if ( myFieldType == QVariant::Int )
        {
            if ( editType == QgsVectorLayer::EditRange )
            {
                QSpinBox *sb = qobject_cast<QSpinBox *>( editor );
                if ( !sb )
                    return false;
                sb->setValue( value.toInt() );
            }
            else
            {
                QAbstractSlider *sl = qobject_cast<QAbstractSlider *>( editor );
                if ( !sl )
                    return false;
                sl->setValue( value.toInt() );
            }
            break;
        }
        else if ( myFieldType == QVariant::Double )
        {
            QDoubleSpinBox *dsb = qobject_cast<QDoubleSpinBox *>( editor );
            if ( !dsb )
                return false;
            dsb->setValue( value.toDouble() );
        }
    }

    case QgsVectorLayer::CheckBox:
    {
        QGroupBox *gb = qobject_cast<QGroupBox *>( editor );
        if ( gb )
        {
            QPair<QString, QString> states = vl->checkedState( idx );
            gb->setChecked( value == states.first );
            break;
        }

        QCheckBox *cb = qobject_cast<QCheckBox *>( editor );
        if ( cb )
        {
            QPair<QString, QString> states = vl->checkedState( idx );
            cb->setChecked( value == states.first );
            break;
        }
    }

    // fall-through

    case QgsVectorLayer::LineEdit:
    case QgsVectorLayer::UniqueValuesEditable:
    case QgsVectorLayer::Immutable:
    case QgsVectorLayer::UuidGenerator:
    default:
    {
        QLineEdit *le = qobject_cast<QLineEdit *>( editor );
        QComboBox *cb = qobject_cast<QComboBox *>( editor );
        QTextEdit *te = qobject_cast<QTextEdit *>( editor );
        QPlainTextEdit *pte = qobject_cast<QPlainTextEdit *>( editor );
        if ( !le && ! cb && !te && !pte )
            return false;

        QString text;
        if ( value.isNull() )
        {
            if ( myFieldType == QVariant::Int || myFieldType == QVariant::Double || myFieldType == QVariant::LongLong )
                text = "";
            else if ( editType == QgsVectorLayer::UuidGenerator )
                text = QUuid::createUuid().toString();
            else
                text = nullValue;
        }
        else
        {
            text = value.toString();
        }

        if ( le )
            le->setText( text );
        if ( cb && cb->isEditable() )
            cb->setEditText( text );
        if ( te )
            te->setHtml( text );
        if ( pte )
            pte->setPlainText( text );
    }
    break;

    case QgsVectorLayer::FileName:
    case QgsVectorLayer::Calendar:
    {
        QCalendarWidget *cw = qobject_cast<QCalendarWidget *>( editor );
        if ( cw )
        {
            cw->setSelectedDate( value.toDate() );
            break;
        }

        QLineEdit* le = qobject_cast<QLineEdit*>( editor );
        if ( !le )
        {
            le = editor->findChild<QLineEdit *>();
        }
        if ( !le )
        {
            return false;
        }
        le->setText( value.toString() );
    }
    break;
    }

    return true;
}
Esempio n. 17
0
int main(int argc, char **argv)
{
    QApplication app(argc, argv);

    QCalendarWidget calendar;
    calendar.setSelectedDate(calendar.selectedDate().addDays(3));
    calendar.setGridVisible(true);
    calendar.show();

    QCalendarWidget calendarMin;
    calendarMin.setMinimumDate(calendarMin.selectedDate().addDays(-7));
    calendarMin.setGridVisible(true);
    calendarMin.show();

    QCalendarWidget calendarMax;
    calendarMax.setMaximumDate(calendarMax.selectedDate().addDays(7));
    calendarMax.setGridVisible(true);
    calendarMax.show();

    return app.exec();
}
Esempio n. 18
0
void tst_QCalendarWidget::showPrevNext()
{
    QFETCH(ShowFunc, function);
    QFETCH(QDate, dateOrigin);
    QFETCH(QDate, expectedDate);

    QCalendarWidget calWidget;
    calWidget.show();
    QVERIFY(QTest::qWaitForWindowExposed(&calWidget));
    if(!dateOrigin.isNull()) {
        calWidget.setSelectedDate(dateOrigin);
        calWidget.setCurrentPage(dateOrigin.year(), dateOrigin.month());

        QCOMPARE(calWidget.yearShown(), dateOrigin.year());
        QCOMPARE(calWidget.monthShown(), dateOrigin.month());
    } else {
        QCOMPARE(calWidget.yearShown(), QDate::currentDate().year());
        QCOMPARE(calWidget.monthShown(), QDate::currentDate().month());
    }

    (calWidget.*function)();

    QCOMPARE(calWidget.yearShown(), expectedDate.year());
    QCOMPARE(calWidget.monthShown(), expectedDate.month());

    // QTBUG-4058
    QTest::qWait(20);
    QToolButton *button = calWidget.findChild<QToolButton *>("qt_calendar_prevmonth");
    QTest::mouseClick(button, Qt::LeftButton);
    expectedDate = expectedDate.addMonths(-1);
    QCOMPARE(calWidget.yearShown(), expectedDate.year());
    QCOMPARE(calWidget.monthShown(), expectedDate.month());

    if(!dateOrigin.isNull()) {
        //the selectedDate should not have changed
        QCOMPARE(calWidget.selectedDate(), dateOrigin);
    }
}
Esempio n. 19
0
void tst_QCalendarWidget::firstDayOfWeek()
{
    // Ensure the default locale is chosen.
    QCalendarWidget calendar;
    QLocale locale;
    QCOMPARE(calendar.firstDayOfWeek(), locale.firstDayOfWeek());

    QLocale germanLocale(QLocale::German);
    QLocale::setDefault(germanLocale);
    QCalendarWidget germanLocaleCalendar;
    QCOMPARE(germanLocaleCalendar.firstDayOfWeek(), germanLocale.firstDayOfWeek());

    // Ensure calling setLocale works as well.
    QLocale frenchLocale(QLocale::French);
    calendar.setLocale(frenchLocale);
    QCOMPARE(calendar.firstDayOfWeek(), frenchLocale.firstDayOfWeek());

    // Ensure that widget-specific locale takes precedence over default.
    QLocale::setDefault(QLocale::English);
    QCOMPARE(calendar.firstDayOfWeek(), frenchLocale.firstDayOfWeek());

    // Ensure that setting the locale of parent widget has an effect.
    QWidget* parent = new QWidget;
    calendar.setParent(parent);
    QLocale hausaLocale(QLocale::Hausa);
    parent->setLocale(hausaLocale);
    QCOMPARE(calendar.firstDayOfWeek(), hausaLocale.firstDayOfWeek());

    // Ensure that widget-specific locale takes precedence over parent.
    calendar.setLocale(germanLocale);
    // Sanity check...
    QCOMPARE(calendar.locale(), germanLocale);
    QCOMPARE(parent->locale(), hausaLocale);
    QCOMPARE(calendar.firstDayOfWeek(), germanLocale.firstDayOfWeek());
}
Esempio n. 20
0
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    QToolBar *bar1 = this->addToolBar("Tools");
    QActionGroup *group1 = new QActionGroup(bar1);

    QAction *drawLineAction = new QAction("Line", bar1);
    drawLineAction->setIcon(QIcon(":/res/line.png"));
    drawLineAction->setToolTip(tr("Draw a line."));
    drawLineAction->setStatusTip(tr("Draw a line."));
    drawLineAction->setCheckable(true);
    drawLineAction->setChecked(true);
    group1->addAction(drawLineAction);
    bar1->addAction(drawLineAction);

    QAction *drawRectAction = new QAction("Rectangle", bar1);
    drawRectAction->setIcon(QIcon(":/res/rect.png"));
    drawRectAction->setToolTip(tr("Draw a rectangle."));
    drawRectAction->setStatusTip(tr("Draw a rectangle."));
    drawRectAction->setCheckable(true);
    group1->addAction(drawRectAction);
    bar1->addAction(drawRectAction);

    QAction *drawCircleAction = new QAction("Circle", bar1);
    drawCircleAction->setIcon(QIcon(":/res/circle.png"));
    drawCircleAction->setToolTip(tr("Draw a circle."));
    drawCircleAction->setStatusTip(tr("Draw a circle."));
    drawCircleAction->setCheckable(true);
    group1->addAction(drawCircleAction);
    bar1->addAction(drawCircleAction);

    // Start circle position
    QAction *drawStartCircleAction = new QAction("Circle", bar1);
    drawStartCircleAction->setIcon(QIcon(":/res/startcircle.png"));
    drawStartCircleAction->setToolTip(tr("Draw start position."));
    drawStartCircleAction->setStatusTip(tr("Draw start position."));
    drawStartCircleAction->setCheckable(true);
    group1->addAction(drawStartCircleAction);
    bar1->addAction(drawStartCircleAction);

    // Goal circle position
    QAction *drawGoalCircleAction = new QAction("Circle", bar1);
    drawGoalCircleAction->setIcon(QIcon(":/res/goalcircle.png"));
    drawGoalCircleAction->setToolTip(tr("Draw goal position."));
    drawGoalCircleAction->setStatusTip(tr("Draw goal position."));
    drawGoalCircleAction->setCheckable(true);
    group1->addAction(drawGoalCircleAction);
    bar1->addAction(drawGoalCircleAction);


    // =================== Save action
    QToolBar *bar2 = this->addToolBar("Tools2");
    QActionGroup *group2 = new QActionGroup(bar2);
    QAction *saveAction = new QAction("Save", bar2);
    saveAction->setIcon(QIcon(":/res/save.png"));
    saveAction->setToolTip(tr("Save to image"));
    saveAction->setStatusTip(tr("Save to image"));
    saveAction->setCheckable(false);
    saveAction->setChecked(false);
    group2->addAction(saveAction);
    bar2->addAction(saveAction);


    // =================== Load action
    QAction *loadAction = new QAction("Load", bar2);
    loadAction->setIcon(QIcon(":/res/load.png"));
    loadAction->setToolTip(tr("Load image"));
    loadAction->setStatusTip(tr("Load image"));
    loadAction->setCheckable(false);
    loadAction->setChecked(false);
    group2->addAction(loadAction);
    bar2->addAction(loadAction);


    // =================== Start action
    QAction *startAction = new QAction("Start", bar2);
    startAction->setIcon(QIcon(":/res/start.png"));
    startAction->setToolTip(tr("Start"));
    startAction->setStatusTip(tr("Start"));
    startAction->setCheckable(false);
    startAction->setChecked(false);
    group2->addAction(startAction);
    bar2->addAction(startAction);


    // =================== Stop action
    QAction *showAction = new QAction("Show Preformance", bar2);
    showAction->setIcon(QIcon(":/res/show.png"));
    showAction->setToolTip(tr("Show Preformance"));
    showAction->setStatusTip(tr("Show Preformance"));
    showAction->setCheckable(false);
    showAction->setChecked(false);
    group2->addAction(showAction);
    bar2->addAction(showAction);


    // =================== Reset action
    QAction *resetAction = new QAction("Reset", bar2);
    resetAction->setIcon(QIcon(":/res/reset.png"));
    resetAction->setToolTip(tr("Reset"));
    resetAction->setStatusTip(tr("Reset"));
    resetAction->setCheckable(false);
    resetAction->setChecked(false);
    group2->addAction(resetAction);
    bar2->addAction(resetAction);


    // Status bar
    QLabel *statusMsg = new QLabel;
    statusBar()->addWidget(statusMsg);


    paintWidget = new PaintWidget(this);

    gridLayout = new QGridLayout(this);
    gridLayout->addWidget(paintWidget, 0, 0, 1, 1);


//    paintWidget->resize(100, 100);
//    paintWidget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    setCentralWidget(paintWidget);


    // Dock widget 1
    //设置主窗体的第一个QDockWidget
    QDockWidget *preferenceDockWidget = new QDockWidget(this);
    //设置第一个QDockWidget的窗口名称
    preferenceDockWidget->setWindowTitle(tr("Preference"));
    //设置第一个QDockWidget的可停靠区域,全部可停靠
    preferenceDockWidget->setAllowedAreas(Qt::AllDockWidgetAreas);
    preferenceDockWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    //设置第一个QDockWidget内的控件并设置该控件的属性

    preferenceWidget = new PreferenceWidget(this);


    QCalendarWidget *calendar = new QCalendarWidget;
    calendar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    calendar->setGridVisible(true);
    //将QCalendarWidget控件设置成QDockWidget的主控件 使其能随窗口大小改变而改变
    preferenceDockWidget->setWidget(preferenceWidget);
    //向主窗体中添加第一个QDockWidget控件 第一个参数表示初始显示的位置 第二个参数是要添加的QDockWidget控件
    this->addDockWidget(Qt::RightDockWidgetArea, preferenceDockWidget);

    // Dock widget 2
    QDockWidget *performanceDockWidget = new QDockWidget(this);
    //设置第一个QDockWidget的窗口名称
    performanceDockWidget->setWindowTitle(tr("Performance"));
    //设置第一个QDockWidget的可停靠区域,全部可停靠
    performanceDockWidget->setAllowedAreas(Qt::AllDockWidgetAreas);
    performanceDockWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    //设置第一个QDockWidget内的控件并设置该控件的属性

    performanceWidget = new PerformanceWidget(this);

    //将QCalendarWidget控件设置成QDockWidget的主控件 使其能随窗口大小改变而改变
    performanceDockWidget->setWidget(performanceWidget);
    //向主窗体中添加第一个QDockWidget控件 第一个参数表示初始显示的位置 第二个参数是要添加的QDockWidget控件
    this->addDockWidget(Qt::RightDockWidgetArea, performanceDockWidget);



    connect(drawLineAction, SIGNAL(triggered()), this, SLOT(drawLineActionTriggered()));
    connect(drawRectAction, SIGNAL(triggered()), this, SLOT(drawRectActionTriggered()));
    connect(drawCircleAction, SIGNAL(triggered()), this, SLOT(drawCircleActionTriggered()));
    connect(drawStartCircleAction, SIGNAL(triggered()), this, SLOT(drawStartCircleActionTriggered()));
    connect(drawGoalCircleAction, SIGNAL(triggered()), this, SLOT(drawGoalCircleActionTriggered()));
    connect(this, SIGNAL(changeCurrentShape(Shape::Code)), paintWidget, SLOT(setCurrentShape(Shape::Code)));

    connect(saveAction, SIGNAL(triggered()), this, SLOT(saveActionTriggered()));
    connect(loadAction, SIGNAL(triggered()), this, SLOT(loadActionTriggered()));
    connect(startAction, SIGNAL(triggered()), this, SLOT(startActionTriggered()));
    connect(showAction, SIGNAL(triggered()), this, SLOT(stopActionTriggered()));
    connect(resetAction, SIGNAL(triggered()), this, SLOT(resetActionTriggered()));

    // when received the signal from the perference widget then send to pain widget
    connect(preferenceWidget, SIGNAL(rrtTextChangedSignal(QString)), paintWidget, SLOT(rrtTextChangedSlot(QString)));

    connect(this, SIGNAL(startSimulationSignal()), paintWidget, SLOT(startSimulationSlot()));
    connect(this, SIGNAL(stopSimulationSignal()), paintWidget, SLOT(stopSimulationSlot()));
    connect(this, SIGNAL(resetSimulationSignal()), paintWidget, SLOT(resetSimulationSlot()));


    // connect the iteration to the display panel
   // connect(paintWidget->getMyRRT(),SIGNAL(currentIterationChanged(int)),preferenceWidget,SLOT(currentIterationChangedSlot(int)));
    connect(paintWidget,SIGNAL(currentIteration(int)),performanceWidget,SLOT(currentIterationChangedSlot(int)));
    connect(paintWidget,SIGNAL(currentNodeCount(int)),performanceWidget,SLOT(currentNodecountChangedSlot(int)));
    connect(paintWidget,SIGNAL(currentPathLength(int)),performanceWidget,SLOT(currentPathLengthChangedSlot(int)));
}