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.cpp4
1 files changed, 4 insertions, 0 deletions
diff --git a/korganizer/kodaymatrix.cpp b/korganizer/kodaymatrix.cpp
index dfc6af7..c55f7d7 100644
--- a/korganizer/kodaymatrix.cpp
+++ b/korganizer/kodaymatrix.cpp
@@ -244,96 +244,97 @@ KODayMatrix::~KODayMatrix()
delete [] days;
delete [] daylbls;
//delete [] events;
delete mToolTip;
}
/*
void KODayMatrix::setStartDate(QDate start)
{
updateView(start);
}
*/
void KODayMatrix::addSelectedDaysTo(DateList& selDays)
{
if (mSelStart == NOSELECTION) {
return;
}
//cope with selection being out of matrix limits at top (< 0)
int i0 = mSelStart;
if (i0 < 0) {
for (int i = i0; i < 0; i++) {
selDays.append(days[0].addDays(i));
}
i0 = 0;
}
//cope with selection being out of matrix limits at bottom (> NUMDAYS-1)
if (mSelEnd > NUMDAYS-1) {
for (int i = i0; i <= NUMDAYS-1; i++) {
selDays.append(days[i]);
}
for (int i = NUMDAYS; i < mSelEnd; i++) {
selDays.append(days[0].addDays(i));
}
// apply normal routine to selection being entirely within matrix limits
} else {
for (int i = i0; i <= mSelEnd; i++) {
selDays.append(days[i]);
}
}
}
bool KODayMatrix::setSelectedDaysFrom(const QDate& start, const QDate& end)
{
+ mRedrawNeeded = true;
bool noSel = (mSelEnd == NOSELECTION && mSelStart == NOSELECTION );
mSelStart = startdate.daysTo(start);
if ( mSelStart < 0 )
mSelStart = 0;
mSelEnd = startdate.daysTo(end);
if ( mSelEnd > NUMDAYS-1 )
mSelEnd = NUMDAYS-1;
if ( mSelEnd < 0 || mSelStart > NUMDAYS-1 ) {
clearSelection();
if ( noSel )
return false;
}
return true;
}
void KODayMatrix::clearSelection()
{
mSelEnd = mSelStart = NOSELECTION;
}
void KODayMatrix::recalculateToday()
{
today = -1;
for (int i=0; i<NUMDAYS; i++) {
//events[i] = 0;
days[i] = startdate.addDays(i);
daylbls[i] = QString::number( KOGlobals::self()->calendarSystem()->day( days[i] ));
// if today is in the currently displayed month, hilight today
if (days[i].year() == QDate::currentDate().year() &&
days[i].month() == QDate::currentDate().month() &&
days[i].day() == QDate::currentDate().day()) {
today = i;
}
}
// qDebug(QString("Today is visible at %1.").arg(today));
}
void KODayMatrix::updateView()
{
updateView(startdate);
}
void KODayMatrix::repaintViewTimed()
{
mRepaintTimer->stop();
repaint(false);
}
@@ -466,141 +467,144 @@ void KODayMatrix::updateEvents()
const QDate& KODayMatrix::getDate(int offset)
{
if (offset < 0 || offset > NUMDAYS-1) {
qDebug("Wrong offset2 %d", offset);
return days[0];
}
return days[offset];
}
QString KODayMatrix::getHolidayLabel(int offset)
{
if (offset < 0 || offset > NUMDAYS-1) {
qDebug("Wrong offset1 %d", offset);
return QString();
}
return mHolidays[offset];
}
int KODayMatrix::getDayIndexFrom(int x, int y)
{
int colModulo = (width()-2) % 7;
int rowModulo = (height()-2) % 6;
#if 0
return 7*(y/daysize.height()) + (KOGlobals::self()->reverseLayout() ?
6 - x/daysize.width() : x/daysize.width());
#endif
int xVal = (x-colModulo/2-2)/daysize.width();
int yVal = (y-rowModulo/2-2)/daysize.height();
return 7*(yVal) + xVal;
}
// ----------------------------------------------------------------------------
// 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;
mSelEnd = mSelStart;
+ mRedrawNeeded = true;
repaint(false);
}
void KODayMatrix::mouseReleaseEvent (QMouseEvent* e)
{
+ mRedrawNeeded = true;
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;
}
+ mRedrawNeeded = true;
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();