author | zautrix <zautrix> | 2005-02-21 13:34:06 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-02-21 13:34:06 (UTC) |
commit | ce261d6197d319d67f7b275813449f36ce42a730 (patch) (side-by-side diff) | |
tree | 6221eef1d00a918127377883eaf76f8162db6772 | |
parent | b4ebc9c227f986369fe9b0193158f3893a29df08 (diff) | |
download | kdepimpi-ce261d6197d319d67f7b275813449f36ce42a730.zip kdepimpi-ce261d6197d319d67f7b275813449f36ce42a730.tar.gz kdepimpi-ce261d6197d319d67f7b275813449f36ce42a730.tar.bz2 |
default button fixes
-rw-r--r-- | libkdepim/kdateedit.cpp | 1 | ||||
-rw-r--r-- | microkde/kdialogbase.cpp | 5 |
2 files changed, 5 insertions, 1 deletions
diff --git a/libkdepim/kdateedit.cpp b/libkdepim/kdateedit.cpp index 946fc0d..3d9e690 100644 --- a/libkdepim/kdateedit.cpp +++ b/libkdepim/kdateedit.cpp @@ -1,181 +1,182 @@ /* This file is part of libkdepim. Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ #include <qapplication.h> #include <qevent.h> #include <qlineedit.h> #include <qpixmap.h> #include <qpushbutton.h> #include <kdatepicker.h> #include <kdebug.h> #include <kglobal.h> #include <kiconloader.h> #include <klocale.h> #include <kmessagebox.h> #include <knotifyclient.h> #include <qpalette.h> #include "kdateedit.h" //#include "kdateedit.moc" KDateEdit::KDateEdit(QWidget *parent, const char *name, bool withoutDP ) : QHBox(parent, name) { dateFormShort = true; withoutDp = withoutDP; mDateEdit = new QLineEdit(this); mDateEdit->setText(KGlobal::locale()->formatDate(QDate::currentDate(),dateFormShort)); setFocusProxy(mDateEdit); mDateEdit->installEventFilter(this); // Highlight Background and Textcolor QPalette palette = QWidget::palette(); unsigned char red, green, blue; red = palette.color( QPalette::Normal , QColorGroup::Background ).red() - 10; green = palette.color( QPalette::Normal , QColorGroup::Background ).green() - 10; blue = palette.color( QPalette::Normal , QColorGroup::Background ).blue() - 10; palette.setColor( QColorGroup::Highlight, QColor(red,green,blue) ); palette.setColor( QColorGroup::HighlightedText, palette.color( QPalette::Normal , QColorGroup::Foreground ) ); mDateEdit->setPalette( palette ); if ( withoutDP ) { mDateFrame = 0; mDateButton = 0; mDatePicker = 0; } else { QPixmap pixmap = SmallIcon("smallcal"); mDateButton = new QPushButton(this); mDateButton->setPixmap(pixmap); mDateFrame = new QVBox(0,0,WType_Popup); // mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised); mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised ); mDateFrame->setLineWidth(3); mDateFrame->hide(); mDatePicker = new KDatePicker(mDateFrame,QDate::currentDate()); connect(mDatePicker,SIGNAL(dateEntered(QDate)),SLOT(setDate(QDate))); connect(mDatePicker,SIGNAL(dateEntered(QDate)),SIGNAL(dateChanged(QDate))); connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(setDate(QDate))); connect(mDatePicker,SIGNAL(dateSelected(QDate)),SIGNAL(dateChanged(QDate))); connect(mDatePicker,SIGNAL(dateSelected(QDate)),mDateFrame,SLOT(hide())); connect(mDateButton,SIGNAL(clicked()),SLOT(toggleDatePicker())); mDateButton->setFocusPolicy( QWidget::NoFocus ); + mDateButton->setAutoDefault( false ); //mDateFrame->resize( 400, 300 ); } connect(mDateEdit,SIGNAL(returnPressed()),SLOT(lineEnterPressed())); connect(mDateEdit,SIGNAL(textChanged(const QString &)), SLOT(textChanged(const QString &))); // 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; /* * This loop uses some math tricks to figure out the offset in days * to the next date the given day of the week occurs. There * are two cases, that the new day is >= the current day, which means * the new day has not occured yet or that the new day < the current day, * which means the new day is already passed (so we need to find the * day in the next week). */ QString dayName; int currentDay = QDate::currentDate().dayOfWeek(); for (int i = 1; i <= 7; ++i) { dayName = KGlobal::locale()->weekDayName(i).lower(); if (i >= currentDay) mKeywordMap[dayName] = i - currentDay; else mKeywordMap[dayName] = 7 - currentDay + i; } mTextChanged = false; mHandleInvalid = false; // QWidget::setTabOrder( mDateEdit, mDateButton ); } KDateEdit::~KDateEdit() { delete mDateFrame; } void KDateEdit::clear() { bool b = mDateEdit->signalsBlocked(); mDateEdit->blockSignals(true); mDateEdit->setText(""); mDateEdit->blockSignals(b); } void KDateEdit::setDate(QDate newDate) { if (!newDate.isValid() && !mHandleInvalid) return; if ( readDate() == newDate ) return; QString dateString = ""; if(newDate.isValid()) dateString = KGlobal::locale()->formatDate( newDate, dateFormShort ); mTextChanged = false; // We do not want to generate a signal here, since we explicity setting // the date bool b = mDateEdit->signalsBlocked(); mDateEdit->blockSignals(true); mDateEdit->setText(dateString); mDateEdit->blockSignals(b); } void KDateEdit::setDate( QDate date,int *cpos,const int key ,const bool dateFormShort) { QString dateForm = dateFormShort ? KGlobal::locale()->dateFormatShort() : KGlobal::locale()->dateFormat(); int begin = dateForm.find("%"); int space = 0; int allStrLength = 0; int strLength = 0; int repeat = 0; // witch? Day, Month or Year switch? while(1){ switch ( dateForm.at(begin + 1).latin1() ) { case 'd':// 16 (month day) strLength = 2; //Ok break; case 'm':// 01 (month) strLength = 2; //Ok break; case 'a':// Mon (Weekday) strLength = KGlobal::locale()->weekDayName(date.dayOfWeek(), true).length(); break; case 'A':// Monday (Weekday) strLength = KGlobal::locale()->weekDayName(date.dayOfWeek(), false).length(); break; diff --git a/microkde/kdialogbase.cpp b/microkde/kdialogbase.cpp index d1f7630..801094a 100644 --- a/microkde/kdialogbase.cpp +++ b/microkde/kdialogbase.cpp @@ -1,172 +1,175 @@ #include <qtabwidget.h> #include <qpushbutton.h> #include <qlayout.h> #include <qframe.h> #include "klocale.h" #include "kdebug.h" #include "kdialogbase.h" KDialogBase::KDialogBase() { } KDialogBase::KDialogBase( QWidget *parent, const char *name, bool modal, const QString &caption, int buttonMask, ButtonCode defaultButton, bool separator, const QString &user1, const QString &user2, const QString &user3) : KDialog( parent, name, modal ) { init( caption, buttonMask, user1, user2 ); - if (findButton( defaultButton ) ) + if (findButton( defaultButton ) ) { (findButton( defaultButton ) )->setFocus(); + (findButton( defaultButton ) )->setDefault( true ); + } } KDialogBase::KDialogBase( int dialogFace, const QString &caption, int buttonMask, ButtonCode defaultButton, QWidget *parent, const char *name, bool modal, bool separator, const QString &user1, const QString &user2, const QString &user3) : KDialog( parent, name, modal ) { init( caption, buttonMask, user1, user2 ); if (findButton( defaultButton ) ) (findButton( defaultButton ) )->setFocus(); } KDialogBase::~KDialogBase() { } void KDialogBase::init( const QString &caption, int buttonMask, const QString &user1 ,const QString &user2 ) { mMainWidget = 0; mTabWidget = 0; mPlainPage = 0; mTopLayout = 0; if ( !caption.isEmpty() ) { setCaption( caption ); } if ( buttonMask & User1 ) { mUser1Button = new QPushButton( user1, this ); connect( mUser1Button, SIGNAL( clicked() ), SLOT( slotUser1() ) ); } else { mUser1Button = 0; } if ( buttonMask & User2 ) { mUser2Button = new QPushButton( user2, this ); connect( mUser2Button, SIGNAL( clicked() ), SLOT( slotUser2() ) ); } else { mUser2Button = 0; } if ( buttonMask & Ok ) { mOkButton = new QPushButton( i18n("Ok"), this ); connect( mOkButton, SIGNAL( clicked() ), SLOT( slotOk() ) ); + mOkButton->setDefault( true ); } else { mOkButton = 0; } if ( buttonMask & Default ) { mDefaultButton = new QPushButton( i18n("Default"), this ); connect( mDefaultButton, SIGNAL( clicked() ), SIGNAL( defaultClicked() ) ); } else { mDefaultButton = 0; } if ( buttonMask & Apply ) { mApplyButton = new QPushButton( i18n("Apply"), this ); connect( mApplyButton, SIGNAL( clicked() ), SLOT( slotApply() ) ); } else { mApplyButton = 0; } if ( buttonMask & Cancel ) { mCancelButton = new QPushButton( i18n("Cancel"), this ); connect( mCancelButton, SIGNAL( clicked() ), SLOT( slotCancel() ) ); } else { mCancelButton = 0; } if ( buttonMask & Close ) { mCloseButton = new QPushButton( i18n("Close"), this ); connect( mCloseButton, SIGNAL( clicked() ), SLOT( slotClose() ) ); } else { mCloseButton = 0; } } QTabWidget *KDialogBase::tabWidget() { if ( !mTabWidget ) { mTabWidget = new QTabWidget( this ); setMainWidget( mTabWidget ); } return mTabWidget; } void KDialogBase::hideButtons() { if ( mUser1Button ) mUser1Button->hide() ; if ( mUser2Button ) mUser2Button->hide() ; if ( mOkButton ) mOkButton->hide() ; if ( mApplyButton ) mApplyButton->hide() ; if ( mDefaultButton ) mDefaultButton->hide(); if ( mCancelButton ) mCancelButton->hide() ; if ( mCloseButton ) mCloseButton->hide() ; } void KDialogBase::initLayout() { delete mTopLayout; mTopLayout = new QVBoxLayout( this ); mTopLayout->setMargin( marginHint() ); mTopLayout->setSpacing( spacingHint() ); mTopLayout->addWidget( mMainWidget ); QBoxLayout *buttonLayout = new QHBoxLayout; mTopLayout->addLayout( buttonLayout ); if ( mUser1Button ) buttonLayout->addWidget( mUser1Button ); if ( mUser2Button ) buttonLayout->addWidget( mUser2Button ); if ( mOkButton ) buttonLayout->addWidget( mOkButton ); if ( mApplyButton ) buttonLayout->addWidget( mApplyButton ); if ( mDefaultButton ) buttonLayout->addWidget( mDefaultButton ); if ( mCancelButton ) buttonLayout->addWidget( mCancelButton ); if ( mCloseButton ) buttonLayout->addWidget( mCloseButton ); } QFrame *KDialogBase::addPage( const QString &name ) { // kdDebug() << "KDialogBase::addPage(): " << name << endl; QFrame *frame = new QFrame( tabWidget() ); tabWidget()->addTab( frame, name ); return frame; } QFrame *KDialogBase::addPage( const QString &name, int, const QPixmap & ) { return addPage( name ); } void KDialogBase::setMainWidget( QWidget *widget ) { kdDebug() << "KDialogBase::setMainWidget()" << endl; mMainWidget = widget; initLayout(); } |