kexi
kexidatetableedit.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "kexidatetableedit.h"
00023
00024 #include <qapplication.h>
00025 #include <qpainter.h>
00026 #include <qvariant.h>
00027 #include <qrect.h>
00028 #include <qpalette.h>
00029 #include <qcolor.h>
00030 #include <qfontmetrics.h>
00031 #include <qdatetime.h>
00032 #include <qcursor.h>
00033 #include <qpoint.h>
00034 #include <qlayout.h>
00035 #include <qtoolbutton.h>
00036 #include <qdatetimeedit.h>
00037 #include <qclipboard.h>
00038
00039 #include <kdebug.h>
00040 #include <klocale.h>
00041 #include <kglobal.h>
00042 #include <kdatepicker.h>
00043 #include <kdatetbl.h>
00044 #include <klineedit.h>
00045 #include <kpopupmenu.h>
00046 #include <kdatewidget.h>
00047
00048 #include <kexiutils/utils.h>
00049
00050
00051 KexiDateTableEdit::KexiDateTableEdit(KexiTableViewColumn &column, QWidget *parent)
00052 : KexiInputTableEdit(column, parent)
00053 {
00054 setName("KexiDateTableEdit");
00055
00057
00058 m_lineedit->setInputMask( m_formatter.inputMask() );
00059 }
00060
00061 KexiDateTableEdit::~KexiDateTableEdit()
00062 {
00063 }
00064
00065 void KexiDateTableEdit::setValueInInternalEditor(const QVariant &value)
00066 {
00067 if (value.isValid() && value.toDate().isValid())
00068 m_lineedit->setText( m_formatter.dateToString( value.toDate() ) );
00069 else
00070 m_lineedit->setText( QString::null );
00071 }
00072
00073 void KexiDateTableEdit::setValueInternal(const QVariant& add_, bool removeOld)
00074 {
00075 if (removeOld) {
00076
00078 QString add(add_.toString());
00079 m_lineedit->setText(add);
00080 m_lineedit->setCursorPosition(add.length());
00081 return;
00082 }
00083 setValueInInternalEditor( m_origValue );
00084 m_lineedit->setCursorPosition(0);
00085 }
00086
00087 void KexiDateTableEdit::setupContents( QPainter *p, bool focused, const QVariant& val,
00088 QString &txt, int &align, int &x, int &y_offset, int &w, int &h )
00089 {
00090 Q_UNUSED(p);
00091 Q_UNUSED(focused);
00092 Q_UNUSED(x);
00093 Q_UNUSED(w);
00094 Q_UNUSED(h);
00095 #ifdef Q_WS_WIN
00096 y_offset = -1;
00097 #else
00098 y_offset = 0;
00099 #endif
00100 if (val.toDate().isValid())
00101 txt = m_formatter.dateToString(val.toDate());
00102
00103 align |= AlignLeft;
00104 }
00105
00106 bool KexiDateTableEdit::valueIsNull()
00107 {
00108
00109 if (m_formatter.isEmpty(m_lineedit->text()))
00110 return true;
00111 return dateValue().isNull();
00112 }
00113
00114 bool KexiDateTableEdit::valueIsEmpty()
00115 {
00116 return valueIsNull();
00117 }
00118
00119 QDate KexiDateTableEdit::dateValue() const
00120 {
00121 return m_formatter.stringToDate( m_lineedit->text() );
00122 }
00123
00124 QVariant KexiDateTableEdit::value()
00125 {
00126 return m_formatter.stringToVariant( m_lineedit->text() );
00127 }
00128
00129 bool KexiDateTableEdit::valueIsValid()
00130 {
00131 if (m_formatter.isEmpty(m_lineedit->text()))
00132 return true;
00133 return m_formatter.stringToDate( m_lineedit->text() ).isValid();
00134 }
00135
00136 void KexiDateTableEdit::handleCopyAction(const QVariant& value, const QVariant& visibleValue)
00137 {
00138 Q_UNUSED(visibleValue);
00139 if (!value.isNull() && value.toDate().isValid())
00140 qApp->clipboard()->setText( m_formatter.dateToString(value.toDate()) );
00141 else
00142 qApp->clipboard()->setText( QString::null );
00143 }
00144
00145 void KexiDateTableEdit::handleAction(const QString& actionName)
00146 {
00147 const bool alreadyVisible = m_lineedit->isVisible();
00148
00149 if (actionName=="edit_paste") {
00150 const QVariant newValue( m_formatter.stringToDate(qApp->clipboard()->text()) );
00151 if (!alreadyVisible) {
00152 emit editRequested();
00153 m_lineedit->clear();
00154 }
00155 setValueInInternalEditor( newValue );
00156 }
00157 else
00158 KexiInputTableEdit::handleAction(actionName);
00159 }
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288 KEXI_CELLEDITOR_FACTORY_ITEM_IMPL(KexiDateEditorFactoryItem, KexiDateTableEdit)
00289
00290 #include "kexidatetableedit.moc"
|