summaryrefslogtreecommitdiffabout
path: root/korganizer/koagendaview.cpp
Side-by-side diff
Diffstat (limited to 'korganizer/koagendaview.cpp') (more/less context) (show whitespace changes)
-rw-r--r--korganizer/koagendaview.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/korganizer/koagendaview.cpp b/korganizer/koagendaview.cpp
index 6428757..b5596d9 100644
--- a/korganizer/koagendaview.cpp
+++ b/korganizer/koagendaview.cpp
@@ -109,192 +109,227 @@ void TimeLabels::drawContents(QPainter *p,int cx, int cy, int cw, int ch)
// if ( globalFlagBlockAgenda )
// return;
// bug: the parameters cx, cy, cw, ch are the areas that need to be
// redrawn, not the area of the widget. unfortunately, this
// code assumes the latter...
// now, for a workaround...
// these two assignments fix the weird redraw bug
cx = contentsX() + 2;
cw = contentsWidth() - 2;
// end of workaround
int cell = ((int)(cy/mCellHeight));
int y = cell * mCellHeight;
QFontMetrics fm = fontMetrics();
QString hour;
QString suffix;
QString fullTime;
int tW = fm.width("24:00i");
while (y < cy + ch) {
p->drawLine(cx,y,cx+tW,y);
hour.setNum(cell);
suffix = "am";
// handle 24h and am/pm time formats
if (KGlobal::locale()->use12Clock()) {
if (cell > 11) suffix = "pm";
if (cell == 0) hour.setNum(12);
if (cell > 12) hour.setNum(cell - 12);
} else {
suffix = ":00";
}
// create string in format of "XX:XX" or "XXpm/am"
fullTime = hour + suffix;
// center and draw the time label
int timeWidth = fm.width(fullTime+"i");
int offset = this->width() - timeWidth;
int borderWidth = 5;
int timeHeight = fm.height();
timeHeight = timeHeight + 2 - ( timeHeight / 4 );
p->drawText(cx -borderWidth + offset, y+ timeHeight, fullTime);
// increment indices
y += mCellHeight;
cell++;
}
}
/**
Calculates the minimum width.
*/
int TimeLabels::minimumWidth() const
{
QFontMetrics fm = fontMetrics();
//TODO: calculate this value
int borderWidth = 4;
// the maximum width possible
int width = fm.width("88:88x") + borderWidth;
return width;
}
/** updates widget's internal state */
void TimeLabels::updateConfig()
{
// set the font
// config->setGroup("Fonts");
// QFont font = config->readFontEntry("TimeBar Font");
setFont(KOPrefs::instance()->mTimeBarFont);
// update geometry restrictions based on new settings
setFixedWidth(minimumWidth());
// update HourSize
mCellHeight = KOPrefs::instance()->mHourSize*4;
resizeContents(50,mRows * mCellHeight);
}
/** update time label positions */
void TimeLabels::positionChanged()
{
int adjustment = mAgenda->contentsY();
setContentsPos(0, adjustment);
}
/** */
void TimeLabels::setAgenda(KOAgenda* agenda)
{
mAgenda = agenda;
}
+void TimeLabels::contentsMousePressEvent ( QMouseEvent * e)
+{
+ mMouseDownY = e->pos().y();
+}
+
+void TimeLabels::contentsMouseMoveEvent ( QMouseEvent * e )
+{
+ int diff = mMouseDownY - e->pos().y();
+ if ( diff < 10 && diff > -10 )
+ return;
+ int tSize = KOPrefs::instance()->mHourSize + (diff/10) ;
+ if ( tSize < 4 )
+ tSize = 4;
+ if ( tSize > 18 )
+ tSize = 18;
+ tSize = (tSize-2)/2;
+ topLevelWidget()->setCaption(i18n("New Agendasize: %1").arg(tSize));
+
+}
+void TimeLabels::contentsMouseReleaseEvent ( QMouseEvent * e )
+{
+ int diff = mMouseDownY - e->pos().y();
+ if ( diff < 10 && diff > -10 )
+ return;
+ int tSize = KOPrefs::instance()->mHourSize + (diff/10);
+ if ( tSize < 4 )
+ tSize = 4;
+ if ( tSize > 18 )
+ tSize = 18;
+ tSize = (tSize/2)*2;
+ if ( tSize == KOPrefs::instance()->mHourSize )
+ return;
+ KOPrefs::instance()->mHourSize = tSize;
+ emit scaleChanged();
+}
/** This is called in response to repaint() */
void TimeLabels::paintEvent(QPaintEvent*)
{
// kdDebug() << "paintevent..." << endl;
// this is another hack!
// QPainter painter(this);
//QString c
repaintContents(contentsX(), contentsY(), visibleWidth(), visibleHeight());
}
////////////////////////////////////////////////////////////////////////////
EventIndicator::EventIndicator(Location loc,QWidget *parent,const char *name)
: QFrame(parent,name)
{
mColumns = 1;
mTopBox = 0;
mLocation = loc;
mTopLayout = 0;
mPaintWidget = 0;
mXOffset = 0;
if (mLocation == Top) mPixmap = SmallIcon("1uparrow");
else mPixmap = SmallIcon("1downarrow");
mEnabled.resize(mColumns);
if (mLocation == Top)
setMaximumHeight(0);
else
setMinimumHeight(mPixmap.height());
}
EventIndicator::~EventIndicator()
{
}
void EventIndicator::drawContents(QPainter *p)
{
// kdDebug() << "======== top: " << contentsRect().top() << " bottom " << // contentsRect().bottom() << " left " << contentsRect().left() << " right " << contentsRect().right() << endl;
KDGanttSplitterHandle* han = 0;
if ( mPaintWidget )
han = mPaintWidget->firstHandle();
if ( ! han ) {
int i;
for(i=0;i<mColumns;++i) {
if (mEnabled[i]) {
int cellWidth = contentsRect().right()/mColumns;
int xOffset = KOGlobals::self()->reverseLayout() ?
(mColumns - 1 - i)*cellWidth + cellWidth/2 -mPixmap.width()/2 :
i*cellWidth + cellWidth/2 -mPixmap.width()/2;
p->drawPixmap(QPoint(xOffset,0),mPixmap);
}
}
} else {
han->repaint();
//mPaintWidget->setBackgroundColor( red );
QPainter pa( han );
int i;
bool setColor = false;
for(i=0;i<mColumns;++i) {
if (mEnabled[i]) {
setColor = true;
int cellWidth = contentsRect().right()/mColumns;
int xOffset = KOGlobals::self()->reverseLayout() ?
(mColumns - 1 - i)*cellWidth + cellWidth/2 -mPixmap.width()/2 :
i*cellWidth + cellWidth/2 -mPixmap.width()/2;
pa.drawPixmap(QPoint(mXOffset + xOffset,0),mPixmap);
//qDebug("222draw pix %d ",xOffset );
}
}
pa.end();
}
}
void EventIndicator::setXOffset( int x )
{
mXOffset = x;
}
void EventIndicator::setPaintWidget( KDGanttMinimizeSplitter * w )
{
mPaintWidget = w;
}
void EventIndicator::changeColumns(int columns)
{
mColumns = columns;
mEnabled.resize(mColumns);
update();
}
@@ -317,192 +352,194 @@ KOAgendaView::KOAgendaView(Calendar *cal,QWidget *parent,const char *name) :
mLayoutDayLabels = 0;
mDayLabelsFrame = 0;
mDayLabels = 0;
bool isRTL = KOGlobals::self()->reverseLayout();
if ( KOPrefs::instance()->mVerticalScreen ) {
mExpandedPixmap = SmallIcon( "1downarrow" );
mNotExpandedPixmap = SmallIcon( "1uparrow" );
} else {
mExpandedPixmap = SmallIcon( isRTL ? "1leftarrow" : "1rightarrow" );
mNotExpandedPixmap = SmallIcon( isRTL ? "1rightarrow" : "1leftarrow" );
}
QBoxLayout *topLayout = new QVBoxLayout(this);
// Create day name labels for agenda columns
mDayLabelsFrame = new QHBox(this);
topLayout->addWidget(mDayLabelsFrame);
mDayLabels = new QFrame (mDayLabelsFrame);
mLayoutDayLabels = new QHBoxLayout(mDayLabels);
// Create agenda splitter
#ifndef KORG_NOSPLITTER
mSplitterAgenda = new QSplitter(Vertical,this);
topLayout->addWidget(mSplitterAgenda);
mSplitterAgenda->setOpaqueResize();
mAllDayFrame = new QHBox(mSplitterAgenda);
QWidget *agendaFrame = new QWidget(mSplitterAgenda);
#else
#if 0
QWidget *mainBox = new QWidget( this );
topLayout->addWidget( mainBox );
QBoxLayout *mainLayout = new QVBoxLayout(mainBox);
mAllDayFrame = new QHBox(mainBox);
mainLayout->addWidget(mAllDayFrame);
mainLayout->setStretchFactor( mAllDayFrame, 0 );
mAllDayFrame->setFocusPolicy(NoFocus);
QWidget *agendaFrame = new QWidget(mainBox);
mainLayout->addWidget(agendaFrame);
mainLayout->setStretchFactor( agendaFrame, 10 );
agendaFrame->setFocusPolicy(NoFocus);
#endif
mSplitterAgenda = new KDGanttMinimizeSplitter( Qt::Vertical, this);
mSplitterAgenda->setMinimizeDirection ( KDGanttMinimizeSplitter::Up );
topLayout->addWidget( mSplitterAgenda );
mAllDayFrame = new QHBox(mSplitterAgenda);
mAllDayFrame->setFocusPolicy(NoFocus);
QWidget *agendaFrame = new QWidget(mSplitterAgenda);
agendaFrame->setFocusPolicy(NoFocus);
#endif
// Create all-day agenda widget
mDummyAllDayLeft = new QVBox( mAllDayFrame );
mExpandButton = new QPushButton(mDummyAllDayLeft);
mExpandButton->setPixmap( mNotExpandedPixmap );
int widebut = mExpandButton->sizeHint().width();
if ( QApplication::desktop()->width() < 480 )
widebut = widebut*2;
else
widebut = (widebut*3) / 2;
//mExpandButton->setSizePolicy( QSizePolicy( QSizePolicy::Fixed,
// QSizePolicy::Fixed ) );
mExpandButton->setFixedSize( widebut, widebut);
connect( mExpandButton, SIGNAL( clicked() ), SIGNAL( toggleExpand() ) );
mExpandButton->setFocusPolicy(NoFocus);
mAllDayAgenda = new KOAgenda(1,mAllDayFrame);
mAllDayAgenda->setFocusPolicy(NoFocus);
QWidget *dummyAllDayRight = new QWidget(mAllDayFrame);
// Create event context menu for all day agenda
mAllDayAgendaPopup = eventPopup();
connect(mAllDayAgenda,SIGNAL(showIncidencePopupSignal(Incidence *)),
mAllDayAgendaPopup,SLOT(showIncidencePopup(Incidence *)));
// Create agenda frame
QGridLayout *agendaLayout = new QGridLayout(agendaFrame,3,3);
// QHBox *agendaFrame = new QHBox(splitterAgenda);
// create event indicator bars
mEventIndicatorTop = new EventIndicator(EventIndicator::Top,agendaFrame);
agendaLayout->addWidget(mEventIndicatorTop,0,1);
mEventIndicatorTop->setPaintWidget( mSplitterAgenda );
mEventIndicatorBottom = new EventIndicator(EventIndicator::Bottom,
agendaFrame);
agendaLayout->addWidget(mEventIndicatorBottom,2,1);
QWidget *dummyAgendaRight = new QWidget(agendaFrame);
agendaLayout->addWidget(dummyAgendaRight,0,2);
// Create time labels
mTimeLabels = new TimeLabels(24,agendaFrame);
agendaLayout->addWidget(mTimeLabels,1,0);
+ connect(mTimeLabels,SIGNAL( scaleChanged()),
+ this,SLOT(updateConfig()));
// Create agenda
mAgenda = new KOAgenda(1,96,KOPrefs::instance()->mHourSize,agendaFrame);
agendaLayout->addMultiCellWidget(mAgenda,1,1,1,2);
agendaLayout->setColStretch(1,1);
mAgenda->setFocusPolicy(NoFocus);
// Create event context menu for agenda
mAgendaPopup = eventPopup();
mAgendaPopup->addAdditionalItem(QIconSet(SmallIcon("bell")),
i18n("Toggle Alarm"),mAgenda,
SLOT(popupAlarm()),true);
connect(mAgenda,SIGNAL(showIncidencePopupSignal(Incidence *)),
mAgendaPopup,SLOT(showIncidencePopup(Incidence *)));
// make connections between dependent widgets
mTimeLabels->setAgenda(mAgenda);
// Update widgets to reflect user preferences
// updateConfig();
// createDayLabels();
// these blank widgets make the All Day Event box line up with the agenda
dummyAllDayRight->setFixedWidth(mAgenda->verticalScrollBar()->width());
dummyAgendaRight->setFixedWidth(mAgenda->verticalScrollBar()->width());
mDummyAllDayLeft->setFixedWidth(mTimeLabels->width());
// Scrolling
connect(mAgenda->verticalScrollBar(),SIGNAL(valueChanged(int)),
mTimeLabels, SLOT(positionChanged()));
connect(mTimeLabels->verticalScrollBar(),SIGNAL(valueChanged(int)),
SLOT(setContentsPos(int)));
// Create/Show/Edit/Delete Event
connect(mAgenda,SIGNAL(newEventSignal(int,int)),
SLOT(newEvent(int,int)));
connect(mAgenda,SIGNAL(newEventSignal(int,int,int,int)),
SLOT(newEvent(int,int,int,int)));
connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int)),
SLOT(newEventAllDay(int,int)));
connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int,int,int)),
SLOT(newEventAllDay(int,int)));
connect(mAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)),
SLOT(newTimeSpanSelected(int,int,int,int)));
connect(mAllDayAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)),
SLOT(newTimeSpanSelectedAllDay(int,int,int,int)));
connect(mAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView()));
connect(mAllDayAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView()));
connect(mAgenda,SIGNAL(editIncidenceSignal(Incidence *)),
SIGNAL(editIncidenceSignal(Incidence *)));
connect(mAllDayAgenda,SIGNAL(editIncidenceSignal(Incidence *)),
SIGNAL(editIncidenceSignal(Incidence *)));
connect(mAgenda,SIGNAL(showIncidenceSignal(Incidence *)),
SIGNAL(showIncidenceSignal(Incidence *)));
connect(mAllDayAgenda,SIGNAL(showIncidenceSignal(Incidence *)),
SIGNAL(showIncidenceSignal(Incidence *)));
connect(mAgenda,SIGNAL(deleteIncidenceSignal(Incidence *)),
SIGNAL(deleteIncidenceSignal(Incidence *)));
connect(mAllDayAgenda,SIGNAL(deleteIncidenceSignal(Incidence *)),
SIGNAL(deleteIncidenceSignal(Incidence *)));
connect(mAgenda,SIGNAL(itemModified(KOAgendaItem *, int )),
SLOT(updateEventDates(KOAgendaItem *, int )));
connect(mAllDayAgenda,SIGNAL(itemModified(KOAgendaItem *, int )),
SLOT(updateEventDates(KOAgendaItem *, int)));
// event indicator update
connect(mAgenda,SIGNAL(lowerYChanged(int)),
SLOT(updateEventIndicatorTop(int)));
connect(mAgenda,SIGNAL(upperYChanged(int)),
SLOT(updateEventIndicatorBottom(int)));
// drag signals
/*
connect(mAgenda,SIGNAL(startDragSignal(Event *)),
SLOT(startDrag(Event *)));
connect(mAllDayAgenda,SIGNAL(startDragSignal(Event *)),
SLOT(startDrag(Event *)));
*/
// synchronize selections
connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ),
mAllDayAgenda, SLOT( deselectItem() ) );
connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ),
mAgenda, SLOT( deselectItem() ) );
connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ),
SIGNAL( incidenceSelected( Incidence * ) ) );
connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ),
SIGNAL( incidenceSelected( Incidence * ) ) );
connect( mAgenda, SIGNAL( resizedSignal() ),
SLOT( updateConfig( ) ) );
connect( mAgenda, SIGNAL( addToCalSignal(Incidence *, Incidence *) ),
SLOT( addToCalSlot(Incidence *, Incidence * ) ) );
connect( mAllDayAgenda, SIGNAL( addToCalSignal(Incidence * ,Incidence *) ),