AnnotationDialog::KDateEdit::KDateEdit( bool isStartEdit, QWidget *parent )
    : KComboBox( parent ),
      defaultValue( QDate::currentDate() ),
      mReadOnly(false),
      mDiscardNextMousePress(false),
      mIsStartEdit( isStartEdit )
{
    setEditable(true);
    setMaxCount(1);       // need at least one entry for popup to work
    value = defaultValue;
    QString today = QDate::currentDate().toString( QString::fromLatin1("dd. MMM yyyy") );
    addItem(QString::fromLatin1( "" ) );
    setCurrentIndex(0);
    setItemText( 0, QString::fromLatin1( "" ));
    setMinimumSize(sizeHint());

    mDateFrame = new QFrame;
    mDateFrame->setWindowFlags(Qt::Popup);
    QVBoxLayout* layout = new QVBoxLayout(mDateFrame);
    mDateFrame->setFrameStyle(QFrame::StyledPanel | QFrame::Raised);
    mDateFrame->setLineWidth(3);
    mDateFrame->hide();
    mDateFrame->installEventFilter(this);

    mDatePicker = new KDatePicker(value, mDateFrame);
    layout->addWidget(mDatePicker);

    connect(lineEdit(),SIGNAL(editingFinished()),SLOT(lineEnterPressed()));
    connect(this,SIGNAL(textChanged(QString)),
            SLOT(slotTextChanged(QString)));

    connect(mDatePicker,SIGNAL(dateEntered(QDate)),SLOT(dateEntered(QDate)));
    connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(dateSelected(QDate)));

    // Create the keyword list. This will be used to match against when the user
    // enters information.
    mKeywordMap[i18n("tomorrow")] = 1;
    mKeywordMap[i18n("today")] = 0;
    mKeywordMap[i18n("yesterday")] = -1;

    QString dayName;
    for (int i = 1; i <= 7; ++i)
    {
        dayName = KGlobal::locale()->calendar()->weekDayName(i).toLower();
        mKeywordMap[dayName] = i + 100;
    }
    lineEdit()->installEventFilter(this);   // handle keyword entry

    mTextChanged = false;
    mHandleInvalid = false;
}
示例#2
0
void kMyMoneyCalendar::init(const QDate &dt)
{
  styleControl = new QPushButton(i18n("Select Style"), this);
  yearForward = new QToolButton(this);
  yearBackward = new QToolButton(this);
  monthForward = new QToolButton(this);
  monthBackward = new QToolButton(this);
  selectMonth = new QToolButton(this);
  selectYear = new QToolButton(this);
  line = new KLineEdit(this);
  val = new KDateValidator(this);
  fontsize = 10;

  d->selectWeek = new QToolButton(this);

  KMenu* kpopupmenuNew = new KMenu(this);
  kpopupmenuNew->addAction(i18n("Week"), this, SLOT(slotSetStyleWeekly()));
  kpopupmenuNew->addAction(i18n("Month"), this, SLOT(slotSetStyleMonthly()));
  styleControl->setMenu(kpopupmenuNew);

  styleControl->setToolTip(i18n("Choose Style"));
  yearForward->setToolTip(i18n("Next year"));
  yearBackward->setToolTip(i18n("Previous year"));
  monthForward->setToolTip(i18n("Next month"));
  monthBackward->setToolTip(i18n("Previous month"));
  d->selectWeek->setToolTip(i18n("Select a week"));
  selectMonth->setToolTip(i18n("Select a month"));
  selectYear->setToolTip(i18n("Select a year"));

  // -----
  setFontSize(10);
  line->setValidator(val);
  line->installEventFilter(this);
  yearForward->setIcon(QIcon(BarIcon("arrow-right-double")));
  yearBackward->setIcon(QIcon(BarIcon("arrow-left-double")));
  monthForward->setIcon(QIcon(BarIcon("arrow-right")));
  monthBackward->setIcon(QIcon(BarIcon("arrow-left")));
  setDate(dt); // set button texts
  connect(table, SIGNAL(dateChanged(QDate)), SLOT(dateChangedSlot(QDate)));
  connect(table, SIGNAL(tableClicked()), SLOT(tableClickedSlot()));
  connect(monthForward, SIGNAL(clicked()), SLOT(monthForwardClicked()));
  connect(monthBackward, SIGNAL(clicked()), SLOT(monthBackwardClicked()));
  connect(yearForward, SIGNAL(clicked()), SLOT(yearForwardClicked()));
  connect(yearBackward, SIGNAL(clicked()), SLOT(yearBackwardClicked()));
  connect(d->selectWeek, SIGNAL(clicked()), SLOT(selectWeekClicked()));
  connect(selectMonth, SIGNAL(clicked()), SLOT(selectMonthClicked()));
  connect(selectYear, SIGNAL(clicked()), SLOT(selectYearClicked()));
  connect(line, SIGNAL(returnPressed()), SLOT(lineEnterPressed()));
  if (table)
    table->setFocus();
}
示例#3
0
void ExtDatePicker::init( const ExtDate &dt )
{
  d = new ExtDatePickerPrivate();

  d->calendar = new ExtCalendarSystemGregorian();

  QBoxLayout * topLayout = new QVBoxLayout(this);

  d->navigationLayout = new QHBoxLayout(topLayout);
  d->navigationLayout->addStretch();
  yearBackward = new QToolButton(this);
  yearBackward->setAutoRaise(true);
  d->navigationLayout->addWidget(yearBackward);
  monthBackward = new QToolButton(this);
  monthBackward ->setAutoRaise(true);
  d->navigationLayout->addWidget(monthBackward);
  d->navigationLayout->addSpacing(KDialog::spacingHint());

  selectMonth = new QToolButton(this);
  selectMonth ->setAutoRaise(true);
  d->navigationLayout->addWidget(selectMonth);
  selectYear = new QToolButton(this);
  selectYear->setToggleButton(true);
  selectYear->setAutoRaise(true);
  d->navigationLayout->addWidget(selectYear);
  d->navigationLayout->addSpacing(KDialog::spacingHint());

  monthForward = new QToolButton(this);
  monthForward ->setAutoRaise(true);
  d->navigationLayout->addWidget(monthForward);
  yearForward = new QToolButton(this);
  yearForward ->setAutoRaise(true);
  d->navigationLayout->addWidget(yearForward);
  d->navigationLayout->addStretch();

  line = new KLineEdit(this);
  val = new ExtDateValidator(this);
  table = new ExtDateTable(this);
  fontsize = KGlobalSettings::generalFont().pointSize();
  if (fontsize == -1)
     fontsize = QFontInfo(KGlobalSettings::generalFont()).pointSize();

  fontsize++; // Make a little bigger

  d->selectWeek = new QComboBox(false, this);  // read only week selection
  d->todayButton = new QToolButton(this);
  d->todayButton->setIconSet(SmallIconSet("today"));

  QToolTip::add(yearForward, i18n("Next year"));
  QToolTip::add(yearBackward, i18n("Previous year"));
  QToolTip::add(monthForward, i18n("Next month"));
  QToolTip::add(monthBackward, i18n("Previous month"));
  QToolTip::add(d->selectWeek, i18n("Select a week"));
  QToolTip::add(selectMonth, i18n("Select a month"));
  QToolTip::add(selectYear, i18n("Select a year"));
  QToolTip::add(d->todayButton, i18n("Select the current day"));

  // -----
  setFontSize(fontsize);
  line->setValidator(val);
  line->installEventFilter( this );
  if (  QApplication::reverseLayout() )
  {
      yearForward->setIconSet(BarIconSet(QString::fromLatin1("2leftarrow")));
      yearBackward->setIconSet(BarIconSet(QString::fromLatin1("2rightarrow")));
      monthForward->setIconSet(BarIconSet(QString::fromLatin1("1leftarrow")));
      monthBackward->setIconSet(BarIconSet(QString::fromLatin1("1rightarrow")));
  }
  else
  {
      yearForward->setIconSet(BarIconSet(QString::fromLatin1("2rightarrow")));
      yearBackward->setIconSet(BarIconSet(QString::fromLatin1("2leftarrow")));
      monthForward->setIconSet(BarIconSet(QString::fromLatin1("1rightarrow")));
      monthBackward->setIconSet(BarIconSet(QString::fromLatin1("1leftarrow")));
  }
  connect(table, SIGNAL(dateChanged(const ExtDate&)), SLOT(dateChangedSlot(const ExtDate&)));
  connect(table, SIGNAL(tableClicked()), SLOT(tableClickedSlot()));
  connect(monthForward, SIGNAL(clicked()), SLOT(monthForwardClicked()));
  connect(monthBackward, SIGNAL(clicked()), SLOT(monthBackwardClicked()));
  connect(yearForward, SIGNAL(clicked()), SLOT(yearForwardClicked()));
  connect(yearBackward, SIGNAL(clicked()), SLOT(yearBackwardClicked()));
  connect(d->selectWeek, SIGNAL(activated(int)), SLOT(weekSelected(int)));
  connect(d->todayButton, SIGNAL(clicked()), SLOT(todayButtonClicked()));
  connect(selectMonth, SIGNAL(clicked()), SLOT(selectMonthClicked()));
  connect(selectYear, SIGNAL(toggled(bool)), SLOT(selectYearClicked()));
  connect(line, SIGNAL(returnPressed()), SLOT(lineEnterPressed()));
  table->setFocus();


  topLayout->addWidget(table);

  QBoxLayout * bottomLayout = new QHBoxLayout(topLayout);
  bottomLayout->addWidget(d->todayButton);
  bottomLayout->addWidget(line);
  bottomLayout->addWidget(d->selectWeek);

  table->setDate(dt);
  dateChangedSlot(dt);  // needed because table emits changed only when newDate != oldDate
}
示例#4
0
bool DDateEdit::eventFilter( QObject* object, QEvent* event )
{
    if ( object == lineEdit() )
    {
        // We only process the focus out event if the text has changed
        // since we got focus
        if ( (event->type() == QEvent::FocusOut) && d->textChanged )
        {
            lineEnterPressed();
            d->textChanged = false;
        }
        else if ( event->type() == QEvent::KeyPress )
        {
            // Up and down arrow keys step the date
            QKeyEvent* keyEvent = (QKeyEvent*)event;

            if ( keyEvent->key() == Qt::Key_Return )
            {
                lineEnterPressed();
                return true;
            }

            int step = 0;

            if ( keyEvent->key() == Qt::Key_Up )
            {
                step = 1;
            }
            else if ( keyEvent->key() == Qt::Key_Down )
            {
                step = -1;
            }

            if ( step && !d->readOnly )
            {
                QDate date = parseDate();

                if ( date.isValid() )
                {
                    date = date.addDays( step );

                    if ( assignDate( date ) )
                    {
                        updateView();
                        emit dateChanged( date );
                        return true;
                    }
                }
            }
        }
    }
    else
    {
        // It's a date picker event
        switch ( event->type() )
        {
            case QEvent::MouseButtonDblClick:
            case QEvent::MouseButtonPress:
            {
                QMouseEvent* mouseEvent = (QMouseEvent*)event;

                if ( !d->popup->rect().contains( mouseEvent->pos() ) )
                {
                    QPoint globalPos = d->popup->mapToGlobal( mouseEvent->pos() );

                    if ( QApplication::widgetAt( globalPos ) == this )
                    {
                        // The date picker is being closed by a click on the
                        // DDateEdit widget. Avoid popping it up again immediately.
                        d->discardNextMousePress = true;
                    }
                }

                break;
            }
            default:
                break;
        }
    }

    return false;
}