summaryrefslogtreecommitdiffabout
path: root/microkde
authorzautrix <zautrix>2005-02-07 06:10:09 (UTC)
committer zautrix <zautrix>2005-02-07 06:10:09 (UTC)
commit301a4a207171549bd87815705d8dcf32ad15559d (patch) (side-by-side diff)
tree715fde2cd0af0c057f767c25d8e67298425b2c82 /microkde
parent961fc44f4092c1f981eb3be4284715e6829f885c (diff)
downloadkdepimpi-301a4a207171549bd87815705d8dcf32ad15559d.zip
kdepimpi-301a4a207171549bd87815705d8dcf32ad15559d.tar.gz
kdepimpi-301a4a207171549bd87815705d8dcf32ad15559d.tar.bz2
new cool feature
Diffstat (limited to 'microkde') (more/less context) (show whitespace changes)
-rw-r--r--microkde/kdatetbl.cpp165
-rw-r--r--microkde/kdatetbl.h63
2 files changed, 228 insertions, 0 deletions
diff --git a/microkde/kdatetbl.cpp b/microkde/kdatetbl.cpp
index 508ce31..fce0e5a 100644
--- a/microkde/kdatetbl.cpp
+++ b/microkde/kdatetbl.cpp
@@ -559,192 +559,357 @@ KDateInternalMonthPicker::contentsMouseMoveEvent(QMouseEvent *e)
if ( activeCol > -1 && differentCell)
{
tmpRow = activeRow;
tmpCol = activeCol;
}
if ( differentCell)
{
activeRow = row;
activeCol = col;
updateCell( row, col /*, false */ ); // mark the new active cell
}
}
if ( tmpRow > -1 ) // repaint the former active cell
updateCell( tmpRow, tmpCol /*, true */ );
}
}
void
KDateInternalMonthPicker::contentsMouseReleaseEvent(QMouseEvent *e)
{
if(!isEnabled())
{
return;
}
// -----
int row, col, pos;
QPoint mouseCoord;
// -----
mouseCoord = e->pos();
row=rowAt(mouseCoord.y());
col=columnAt(mouseCoord.x());
if(row<0 || col<0)
{ // the user clicked on the frame of the table
emit(closeMe(0));
}
pos=3*row+col+1;
result=pos;
emit(closeMe(1));
}
KDateInternalYearSelector::KDateInternalYearSelector
(int fontsize, QWidget* parent, const char* name)
: QLineEdit(parent, name),
val(new QIntValidator(this)),
result(0)
{
QFont font;
// -----
font=KGlobalSettings::generalFont();
font.setPointSize(fontsize);
setFont(font);
#if 0
setFrameStyle(QFrame::NoFrame);
#endif
// we have to respect the limits of QDate here, I fear:
val->setRange(0, 8000);
setValidator(val);
connect(this, SIGNAL(returnPressed()), SLOT(yearEnteredSlot()));
}
void
KDateInternalYearSelector::yearEnteredSlot()
{
bool ok;
int year;
QDate date;
// ----- check if this is a valid year:
year=text().toInt(&ok);
if(!ok)
{
KNotifyClient::beep();
return;
}
date.setYMD(year, 1, 1);
if(!date.isValid())
{
KNotifyClient::beep();
return;
}
result=year;
emit(closeMe(1));
}
int
KDateInternalYearSelector::getYear()
{
return result;
}
void
KDateInternalYearSelector::setYear(int year)
{
QString temp;
// -----
temp.setNum(year);
setText(temp);
}
KPopupFrame::KPopupFrame(QWidget* parent, const char* name)
: QFrame(parent, name, WType_Popup),
result(0), // rejected
main(0)
{
setFrameStyle(QFrame::Box|QFrame::Raised);
setMidLineWidth(2);
}
void
KPopupFrame::keyPressEvent(QKeyEvent* e)
{
if(e->key()==Key_Escape)
{
result=0; // rejected
qApp->exit_loop();
}
}
void
KPopupFrame::close(int r)
{
result=r;
qApp->exit_loop();
}
void
KPopupFrame::setMainWidget(QWidget* m)
{
main=m;
if(main!=0)
{
resize(main->width()+2*frameWidth(), main->height()+2*frameWidth());
}
}
void
KPopupFrame::resizeEvent(QResizeEvent*)
{
if(main!=0)
{
main->setGeometry(frameWidth(), frameWidth(),
width()-2*frameWidth(), height()-2*frameWidth());
}
}
void
KPopupFrame::popup(const QPoint &pos)
{
// Make sure the whole popup is visible.
QRect d = QApplication::desktop()->frameGeometry();
int x = pos.x();
int y = pos.y();
int w = width();
int h = height();
if (x+w > d.x()+d.width())
x = d.width() - w;
if (y+h > d.y()+d.height())
y = d.height() - h;
if (x < d.x())
x = 0;
if (y < d.y())
y = 0;
// Pop the thingy up.
move(x, y);
show();
}
int
KPopupFrame::exec(QPoint pos)
{
popup(pos);
repaint();
qApp->enter_loop();
hide();
return result;
}
int
KPopupFrame::exec(int x, int y)
{
return exec(QPoint(x, y));
}
void KPopupFrame::virtual_hook( int, void* )
{ /*BASE::virtual_hook( id, data );*/ }
void KDateTable::virtual_hook( int, void* )
{ /*BASE::virtual_hook( id, data );*/ }
//#include "kdatetbl.moc"
+
+
+KDateInternalWeekPicker::KDateInternalWeekPicker
+(int fontsize, QWidget* parent, const char* name)
+ : QGridView(parent, name),
+ result(0) // invalid
+{
+ QRect rect;
+ QFont font;
+ // -----
+ activeCol = -1;
+ activeRow = -1;
+ font=KGlobalSettings::generalFont();
+ font.setPointSize(fontsize);
+ setFont(font);
+ setHScrollBarMode(AlwaysOff);
+ setVScrollBarMode(AlwaysOff);
+ setFrameStyle(QFrame::NoFrame);
+ setNumRows(13);
+ setNumCols(4);
+ // enable to find drawing failures:
+ // setTableFlags(Tbl_clipCellPainting);
+#if 0
+ viewport()->setEraseColor(lightGray); // for consistency with the datepicker
+#endif
+ // ----- find the preferred size
+ // (this is slow, possibly, but unfortunatly it is needed here):
+ QFontMetrics metrics(font);
+ for(int i=1; i <= 52; ++i)
+ {
+ rect=metrics.boundingRect(QString::number( i ));
+ if(max.width()<rect.width()) max.setWidth(rect.width());
+ if(max.height()<rect.height()) max.setHeight(rect.height());
+ }
+
+}
+
+QSize
+KDateInternalWeekPicker::sizeHint() const
+{
+ return QSize((max.width()+6)*numCols()+2*frameWidth(),
+ (max.height()+6)*numRows()+2*frameWidth());
+}
+
+int
+KDateInternalWeekPicker::getResult() const
+{
+ return result;
+}
+
+void
+KDateInternalWeekPicker::setupPainter(QPainter *p)
+{
+ p->setPen(black);
+}
+
+void
+KDateInternalWeekPicker::viewportResizeEvent(QResizeEvent*)
+{
+ setCellWidth(width()/4);
+ setCellHeight(height()/13);
+}
+
+void
+KDateInternalWeekPicker::paintCell(QPainter* painter, int row, int col)
+{
+ int index;
+ QString text;
+ // ----- find the number of the cell:
+ index=4*row+col+1;
+ text=QString::number( index );
+ painter->drawText(0, 0, cellWidth(), cellHeight(), AlignCenter, text);
+ if ( activeCol == col && activeRow == row )
+ painter->drawRect( 0, 0, cellWidth(), cellHeight() );
+}
+
+void
+KDateInternalWeekPicker::contentsMousePressEvent(QMouseEvent *e)
+{
+ if(!isEnabled() || e->button() != LeftButton)
+ {
+ KNotifyClient::beep();
+ return;
+ }
+ // -----
+ int row, col;
+ QPoint mouseCoord;
+ // -----
+ mouseCoord = e->pos();
+ row=rowAt(mouseCoord.y());
+ col=columnAt(mouseCoord.x());
+
+ if(row<0 || col<0)
+ { // the user clicked on the frame of the table
+ activeCol = -1;
+ activeRow = -1;
+ } else {
+ activeCol = col;
+ activeRow = row;
+ updateCell( row, col /*, false */ );
+ }
+}
+
+void
+KDateInternalWeekPicker::contentsMouseMoveEvent(QMouseEvent *e)
+{
+ if (e->state() & LeftButton)
+ {
+ int row, col;
+ QPoint mouseCoord;
+ // -----
+ mouseCoord = e->pos();
+ row=rowAt(mouseCoord.y());
+ col=columnAt(mouseCoord.x());
+ int tmpRow = -1, tmpCol = -1;
+ if(row<0 || col<0)
+ { // the user clicked on the frame of the table
+ if ( activeCol > -1 )
+ {
+ tmpRow = activeRow;
+ tmpCol = activeCol;
+ }
+ activeCol = -1;
+ activeRow = -1;
+ } else {
+ bool differentCell = (activeRow != row || activeCol != col);
+ if ( activeCol > -1 && differentCell)
+ {
+ tmpRow = activeRow;
+ tmpCol = activeCol;
+ }
+ if ( differentCell)
+ {
+ activeRow = row;
+ activeCol = col;
+ updateCell( row, col /*, false */ ); // mark the new active cell
+ }
+ }
+ if ( tmpRow > -1 ) // repaint the former active cell
+ updateCell( tmpRow, tmpCol /*, true */ );
+ }
+}
+
+void
+KDateInternalWeekPicker::contentsMouseReleaseEvent(QMouseEvent *e)
+{
+ if(!isEnabled())
+ {
+ return;
+ }
+ // -----
+ int row, col, pos;
+ QPoint mouseCoord;
+ // -----
+ mouseCoord = e->pos();
+ row=rowAt(mouseCoord.y());
+ col=columnAt(mouseCoord.x());
+ if(row<0 || col<0)
+ { // the user clicked on the frame of the table
+ emit(closeMe(0));
+ }
+ pos=4*row+col+1;
+ result=pos;
+ emit(closeMe(1));
+}
diff --git a/microkde/kdatetbl.h b/microkde/kdatetbl.h
index b4d3e16..2efa532 100644
--- a/microkde/kdatetbl.h
+++ b/microkde/kdatetbl.h
@@ -118,192 +118,255 @@ public:
void setYear(int year);
private:
class KDateInternalYearPrivate;
KDateInternalYearPrivate *d;
};
/**
* Frame with popup menu behaviour.
* @author Tim Gilman, Mirko Boehm
* @version $Id$
*/
class KPopupFrame : public QFrame
{
Q_OBJECT
protected:
/**
* The result. It is returned from exec() when the popup window closes.
*/
int result;
/**
* Catch key press events.
*/
void keyPressEvent(QKeyEvent* e);
/**
* The only subwidget that uses the whole dialog window.
*/
QWidget *main;
public slots:
/**
* Close the popup window. This is called from the main widget, usually.
* @p r is the result returned from exec().
*/
void close(int r);
public:
/**
* The contructor. Creates a dialog without buttons.
*/
KPopupFrame(QWidget* parent=0, const char* name=0);
/**
* Set the main widget. You cannot set the main widget from the constructor,
* since it must be a child of the frame itselfes.
* Be careful: the size is set to the main widgets size. It is up to you to
* set the main widgets correct size before setting it as the main
* widget.
*/
void setMainWidget(QWidget* m);
/**
* The resize event. Simply resizes the main widget to the whole
* widgets client size.
*/
void resizeEvent(QResizeEvent*);
/**
* Open the popup window at position pos.
*/
void popup(const QPoint &pos);
/**
* Execute the popup window.
*/
int exec(QPoint p);
/**
* Dito.
*/
int exec(int x, int y);
private:
virtual bool close(bool alsoDelete) { return QFrame::close(alsoDelete); }
protected:
virtual void virtual_hook( int id, void* data );
private:
class KPopupFramePrivate;
KPopupFramePrivate *d;
};
/**
* Validates user-entered dates.
*/
class KDateValidator : public QValidator
{
public:
KDateValidator(QWidget* parent=0, const char* name=0);
virtual State validate(QString&, int&) const;
virtual void fixup ( QString & input ) const;
State date(const QString&, QDate&) const;
};
/**
* Date selection table.
* This is a support class for the KDatePicker class. It just
* draws the calender table without titles, but could theoretically
* be used as a standalone.
*
* When a date is selected by the user, it emits a signal:
* dateSelected(QDate)
*
* @internal
* @version $Id$
* @author Tim Gilman, Mirko Boehm
*/
class KDateTable : public QGridView
{
Q_OBJECT
public:
/**
* The constructor.
*/
KDateTable(QWidget *parent=0,
QDate date=QDate::currentDate(),
const char* name=0, WFlags f=0);
/**
* Returns a recommended size for the widget.
* To save some time, the size of the largest used cell content is
* calculated in each paintCell() call, since all calculations have
* to be done there anyway. The size is stored in maxCell. The
* sizeHint() simply returns a multiple of maxCell.
*/
virtual QSize sizeHint() const;
/**
* Set the font size of the date table.
*/
void setFontSize(int size);
/**
* Select and display this date.
*/
bool setDate(const QDate&);
const QDate& getDate() const;
protected:
bool mMarkCurrent;
/**
* Paint a cell.
*/
virtual void paintCell(QPainter*, int, int);
/**
* Handle the resize events.
*/
virtual void viewportResizeEvent(QResizeEvent *);
/**
* React on mouse clicks that select a date.
*/
virtual void contentsMousePressEvent(QMouseEvent *);
virtual void keyPressEvent( QKeyEvent *e );
virtual void focusInEvent( QFocusEvent *e );
virtual void focusOutEvent( QFocusEvent *e );
/**
* The font size of the displayed text.
*/
int fontsize;
/**
* The currently selected date.
*/
QDate date;
/**
* The day of the first day in the month [1..7].
*/
int firstday;
/**
* The number of days in the current month.
*/
int numdays;
/**
* The number of days in the previous month.
*/
int numDaysPrevMonth;
/**
* unused
*/
bool unused_hasSelection;
/**
* Save the size of the largest used cell content.
*/
QRect maxCell;
signals:
/**
* The selected date changed.
*/
void dateChanged(QDate);
/**
* A date has been selected by clicking on the table.
*/
void tableClicked();
protected:
virtual void virtual_hook( int id, void* data );
private:
class KDateTablePrivate;
KDateTablePrivate *d;
};
#endif // KDATETBL_H
+class KDateInternalWeekPicker : public QGridView
+{
+ Q_OBJECT
+protected:
+ /**
+ * Store the month that has been clicked [1..12].
+ */
+ int result;
+ /**
+ * the cell under mouse cursor when LBM is pressed
+ */
+ short int activeCol;
+ short int activeRow;
+ /**
+ * Contains the largest rectangle needed by the month names.
+ */
+ QRect max;
+signals:
+ /**
+ * This is send from the mouse click event handler.
+ */
+ void closeMe(int);
+public:
+ /**
+ * The constructor.
+ */
+ KDateInternalWeekPicker(int fontsize, QWidget* parent, const char* name=0);
+ /**
+ * The size hint.
+ */
+ QSize sizeHint() const;
+ /**
+ * Return the result. 0 means no selection (reject()), 1..12 are the
+ * months.
+ */
+ int getResult() const;
+protected:
+ /**
+ * Set up the painter.
+ */
+ void setupPainter(QPainter *p);
+ /**
+ * The resize event.
+ */
+ void viewportResizeEvent(QResizeEvent*);
+ /**
+ * Paint a cell. This simply draws the month names in it.
+ */
+ virtual void paintCell(QPainter* painter, int row, int col);
+ /**
+ * Catch mouse click and move events to paint a rectangle around the item.
+ */
+ void contentsMousePressEvent(QMouseEvent *e);
+ void contentsMouseMoveEvent(QMouseEvent *e);
+ /**
+ * Emit monthSelected(int) when a cell has been released.
+ */
+ void contentsMouseReleaseEvent(QMouseEvent *e);
+
+private:
+ class KDateInternalMonthPrivate;
+ KDateInternalMonthPrivate *d;
+};