summaryrefslogtreecommitdiffabout
path: root/korganizer/kodaymatrix.cpp
Side-by-side diff
Diffstat (limited to 'korganizer/kodaymatrix.cpp') (more/less context) (show whitespace changes)
-rw-r--r--korganizer/kodaymatrix.cpp89
1 files changed, 75 insertions, 14 deletions
diff --git a/korganizer/kodaymatrix.cpp b/korganizer/kodaymatrix.cpp
index 9181936..15a1cb4 100644
--- a/korganizer/kodaymatrix.cpp
+++ b/korganizer/kodaymatrix.cpp
@@ -430,380 +430,441 @@ const QDate& KODayMatrix::getDate(int offset)
return days[0];
}
return days[offset];
}
QString KODayMatrix::getHolidayLabel(int offset)
{
if (offset < 0 || offset > NUMDAYS-1) {
qDebug("Wrong offset1 ");
return 0;
}
return mHolidays[offset];
}
int KODayMatrix::getDayIndexFrom(int x, int y)
{
return 7*(y/daysize.height()) + (KOGlobals::self()->reverseLayout() ?
6 - x/daysize.width() : x/daysize.width());
}
// ----------------------------------------------------------------------------
// M O U S E E V E N T H A N D L I N G
// ----------------------------------------------------------------------------
void KODayMatrix::mousePressEvent (QMouseEvent* e)
{
if ( e->button() == LeftButton )
mouseDown = true;
mSelStart = getDayIndexFrom(e->x(), e->y());
if (mSelStart > NUMDAYS-1) mSelStart=NUMDAYS-1;
mSelInit = mSelStart;
}
void KODayMatrix::mouseReleaseEvent (QMouseEvent* e)
{
if ( e->button() == LeftButton )
if ( ! mouseDown ) {
return;
}
else
mouseDown = false;
int tmp = getDayIndexFrom(e->x(), e->y());
if (tmp > NUMDAYS-1) tmp=NUMDAYS-1;
if (mSelInit > tmp) {
mSelEnd = mSelInit;
if (tmp != mSelStart) {
mSelStart = tmp;
repaint(false);
}
} else {
mSelStart = mSelInit;
//repaint only if selection has changed
if (tmp != mSelEnd) {
mSelEnd = tmp;
repaint(false);
}
}
DateList daylist;
if ( mSelStart < 0 )
mSelStart = 0;
for (int i = mSelStart; i <= mSelEnd; i++) {
daylist.append(days[i]);
}
emit selected((const DateList)daylist);
}
void KODayMatrix::mouseMoveEvent (QMouseEvent* e)
{
if ( ! mouseDown ) {
return;
}
int tmp = getDayIndexFrom(e->x(), e->y());
if (tmp > NUMDAYS-1) tmp=NUMDAYS-1;
if (mSelInit > tmp) {
mSelEnd = mSelInit;
if (tmp != mSelStart) {
mSelStart = tmp;
repaint(false);
}
} else {
mSelStart = mSelInit;
//repaint only if selection has changed
if (tmp != mSelEnd) {
mSelEnd = tmp;
repaint(false);
}
}
}
// ----------------------------------------------------------------------------
// D R A G ' N D R O P H A N D L I N G
// ----------------------------------------------------------------------------
void KODayMatrix::dragEnterEvent(QDragEnterEvent *e)
{
#ifndef KORG_NODND
if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) {
e->ignore();
return;
}
// some visual feedback
// oldPalette = palette();
// setPalette(my_HilitePalette);
// update();
#endif
}
void KODayMatrix::dragMoveEvent(QDragMoveEvent *e)
{
#ifndef KORG_NODND
if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) {
e->ignore();
return;
}
e->accept();
#endif
}
void KODayMatrix::dragLeaveEvent(QDragLeaveEvent */*dl*/)
{
#ifndef KORG_NODND
// setPalette(oldPalette);
// update();
#endif
}
void KODayMatrix::dropEvent(QDropEvent *e)
{
#ifndef KORG_NODND
// kdDebug() << "KODayMatrix::dropEvent(e) begin" << endl;
if (!mCalendar || !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) {
e->ignore();
return;
}
DndFactory factory( mCalendar );
Event *event = factory.createDrop(e);
if (event) {
e->acceptAction();
Event *existingEvent = mCalendar->event(event->uid());
if(existingEvent) {
// uniquify event
event->recreate();
/*
KMessageBox::sorry(this,
i18n("Event already exists in this calendar."),
i18n("Drop Event"));
delete event;
return;
*/
}
// kdDebug() << "Drop new Event" << endl;
// Adjust date
QDateTime start = event->dtStart();
QDateTime end = event->dtEnd();
int duration = start.daysTo(end);
int idx = getDayIndexFrom(e->pos().x(), e->pos().y());
start.setDate(days[idx]);
end.setDate(days[idx].addDays(duration));
event->setDtStart(start);
event->setDtEnd(end);
mCalendar->addEvent(event);
emit eventDropped(event);
} else {
// kdDebug() << "KODayMatrix::dropEvent(): Event from drop not decodable" << endl;
e->ignore();
}
#endif
}
// ----------------------------------------------------------------------------
// P A I N T E V E N T H A N D L I N G
// ----------------------------------------------------------------------------
void KODayMatrix::paintEvent(QPaintEvent * pevent)
{
- if ( width() <= 0 || height() <= 0 )
+ QRect sz = frameRect();
+ if ( sz.width() <= 0 || sz.height() <= 0 )
return;
if ( mPendingUpdateBeforeRepaint ) {
updateViewTimed();
mPendingUpdateBeforeRepaint = false;
}
- if ( myPix.width() != width() || myPix.height()!=height() ) {
- myPix.resize(size() );
+ if ( myPix.width() != sz.width() || myPix.height()!=sz.height() ) {
+ myPix.resize(sz.size() );
}
QPainter p(&myPix);
p.setFont(font());
- QRect sz = frameRect();
+
int dheight = daysize.height();
int dwidth = daysize.width();
int row,col;
int selw, selh;
+ int xyOff = frameWidth();
+ int colModulo = sz.width() % 7;
+ int rowModulo = sz.height() % 6;
+ qDebug("off %d col %d row %d ",xyOff,colModulo,rowModulo );
+
bool isRTL = KOGlobals::self()->reverseLayout();
// draw background and topleft frame
p.fillRect(pevent->rect(), mDefaultBackColor);
p.setPen(mDefaultTextColor);
p.drawRect(0, 0, sz.width()+1, sz.height()+1);
int mSelStartT = mSelStart;
int mSelEndT = mSelEnd;
if ( mSelEndT >= NUMDAYS )
mSelEndT = NUMDAYS-1;
// draw selected days with highlighted background color
if (mSelStart != NOSELECTION) {
bool skip = false;
if ( ! mouseDown ) {
int mo = days[20].month();
//qDebug("-- %d %d ", mSelStartT, mSelEndT);
//qDebug("%d %d %d - d %d", mo, days[mSelStartT].month() , days[mSelEndT].month(), days[mSelEndT].day() );
if ( days[mSelStartT].month() > mo || days[mSelEndT].month() < mo ) {
skip = true;
} else {
if ( days[mSelStartT].month() != mo ) {
int add = days[mSelStartT].daysInMonth ()-days[mSelStartT].day();
mSelStartT += add +1;
}
if ( days[mSelEndT].month() != mo ) {
int sub = days[mSelEndT].day();
mSelEndT -= sub ;
}
}
}
if ( ! skip ) {
row = mSelStartT/7;
col = mSelStartT -row*7;
QColor selcol = KOPrefs::instance()->mHighlightColor;
+
+
+ int addCol = 0;
+ int addRow = 0;
+#if 0
+ if ( colModulo ) {
+ if ( col >= 7 - colModulo )
+ addCol = col - 7 + colModulo;
+ }
+ if ( rowModulo ) {
+ if ( row >= 6 - rowModulo )
+ addRow = row - 5 + rowModulo;
+ }
+#endif
+
+
+
+
+
if (row == mSelEndT/7) {
+ if ( rowModulo ) {
+ if ( row >= 6 - rowModulo )
+ addRow = row - 5 + rowModulo;
+ }
+ if ( colModulo ) {
+ if ( mSelEndT-mSelStartT+1 >= 7 - colModulo )
+ addCol = mSelEndT-mSelStartT+1 - 7 + colModulo;
+ }
// Single row selection
- p.fillRect(isRTL ? (7 - (mSelEndT-mSelStartT+1) - col)*dwidth : col*dwidth,
- row*dheight, (mSelEndT-mSelStartT+1)*dwidth, dheight, selcol);
+ if ( row == 0)
+ addRow = 1;
+ p.fillRect(isRTL ? (7 - (mSelEndT-mSelStartT+1) - col)*dwidth : col*dwidth+1,
+ row*dheight+addRow, (mSelEndT-mSelStartT+1)*dwidth+addCol, dheight+1, selcol);
} else {
// draw first row to the right
- p.fillRect(isRTL ? 0 : col*dwidth, row*dheight, (7-col)*dwidth,
+ if ( row == 0)
+ addRow = 1;
+ p.fillRect(isRTL ? 0 : col*dwidth+1, row*dheight+addRow, (7-col)*dwidth+colModulo,
dheight, selcol);
// draw full block till last line
selh = mSelEndT/7-row;
if (selh > 1) {
- p.fillRect(0, (row+1)*dheight, 7*dwidth, (selh-1)*dheight,selcol);
+ p.fillRect(1, (row+1)*dheight, 7*dwidth+colModulo, (selh-1)*dheight,selcol);
}
// draw last block from left to mSelEndT
selw = mSelEndT-7*(mSelEndT/7)+1;
- p.fillRect(isRTL ? (7-selw)*dwidth : 0, (row+selh)*dheight,
- selw*dwidth, dheight, selcol);
+ //qDebug("esl %d ",selw );
+ int add = 0;
+ if ( colModulo ) {
+ add = 7 - colModulo;
+ if ( selw > add )
+ add = selw - add;
+ else
+ add = 0;
+ }
+ //qDebug("add %d ", add);
+ p.fillRect(isRTL ? (7-selw)*dwidth : 1, (row+selh)*dheight,
+ selw*dwidth+add, dheight, selcol);
}
}
}
// iterate over all days in the matrix and draw the day label in appropriate colors
QColor actcol = mDefaultTextColorShaded;
p.setPen(actcol);
QPen tmppen;
for(int i = 0; i < NUMDAYS; i++) {
row = i/7;
col = isRTL ? 6-(i-row*7) : i-row*7;
// if it is the first day of a month switch color from normal to shaded and vice versa
if ( KOGlobals::self()->calendarSystem()->day( days[i] ) == 1) {
if (actcol == mDefaultTextColorShaded) {
actcol = mDefaultTextColor;
} else {
actcol = mDefaultTextColorShaded;
}
p.setPen(actcol);
}
if (actcol == mDefaultTextColorShaded) {
if ( ! mouseDown ) {
continue;
}
}
//Reset pen color after selected days block
if (i == mSelEndT+1) {
p.setPen(actcol);
}
// if today then draw rectangle around day
if (today == i) {
tmppen = p.pen();
QPen mTodayPen(p.pen());
mTodayPen.setWidth(mTodayMarginWidth);
//draw red rectangle for holidays
if (!mHolidays[i].isNull()) {
if (actcol == mDefaultTextColor) {
mTodayPen.setColor(KOPrefs::instance()->mHolidayColor);
} else {
mTodayPen.setColor(mHolidayColorShaded);
}
}
//draw gray rectangle for today if in selection
if (i >= mSelStartT && i <= mSelEndT) {
QColor grey("grey");
mTodayPen.setColor(grey);
}
p.setPen(mTodayPen);
p.drawRect(col*dwidth, row*dheight, dwidth, dheight);
p.setPen(tmppen);
}
// if any events are on that day then draw it using a bold font
if (events[i] > 0) {
QFont myFont = font();
myFont.setBold(true);
p.setFont(myFont);
}
// if it is a holiday then use the default holiday color
if (!mHolidays[i].isNull()) {
if ( bDays.testBit(i) ) {
p.setPen(Qt::green);
} else {
if (actcol == mDefaultTextColor) {
p.setPen(KOPrefs::instance()->mHolidayColor);
} else {
p.setPen(mHolidayColorShaded);
}
}
}
// draw selected days with special color
// DO NOT specially highlight holidays in selection !
if (i >= mSelStartT && i <= mSelEndT) {
;//p.setPen(mSelectedDaysColor);
}
- p.drawText(col*dwidth, row*dheight, dwidth, dheight,
+ int addCol = 0;
+ int addRow = 0;
+ if ( colModulo ) {
+ if ( col >= 7 - colModulo )
+ addCol = col - 7 + colModulo;
+ }
+ if ( rowModulo ) {
+ if ( row >= 6 - rowModulo )
+ addRow = row - 5 + rowModulo;
+ }
+ //qDebug("add %d %d -- %d %d ", col, addCol, row, addRow);
+ ++addCol;++addCol;
+ p.drawText(col*dwidth+addCol, row*dheight+addRow, dwidth, dheight,
Qt::AlignHCenter | Qt::AlignVCenter, daylbls[i]);
// reset color to actual color
if (!mHolidays[i].isNull()) {
p.setPen(actcol);
}
// reset bold font to plain font
if (events[i] > 0) {
QFont myFont = font();
myFont.setBold(false);
p.setFont(myFont);
}
}
- bitBlt (this, 0, 0, &myPix, 0 ,0,width(), height() ,CopyROP);
+ int off = xyOff;
+ bitBlt (this, off, off, &myPix, 0 ,0,width(), height() ,CopyROP);
+ //qDebug("ffffffffff %d ", off);
}
// ----------------------------------------------------------------------------
// R E SI Z E E V E N T H A N D L I N G
// ----------------------------------------------------------------------------
void KODayMatrix::resizeEvent(QResizeEvent *)
{
QRect sz = frameRect();
daysize.setHeight(sz.height()*7 / NUMDAYS);
daysize.setWidth(sz.width() / 7);
}
QSize KODayMatrix::sizeHint() const
{
QFontMetrics fm ( font() );
- int wid = fm.width( "30") *7+7;
- int hei = fm.height() * 6+4;
+ int wid = fm.width( "30") *7+3;
+ int hei = fm.height() * 6+3;
//qDebug("KODayMatrix::sizeHint()********************* %d %d", wid , hei);
return QSize ( wid, hei );
}