Changeset be12b9f


Ignore:
Timestamp:
08/23/11 20:43:56 (10 years ago)
Author:
Philipp Spitzer <philipp@…>
Branches:
master, qt5
Children:
ec813bb
Parents:
5dbcd35
Message:

Changed the drawing of events to make use of system colors and styles, at least partially.

Location:
src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/gui/tabcontainer.ui

    r5dbcd35 rbe12b9f  
    3333         <verstretch>1</verstretch>
    3434        </sizepolicy>
     35       </property>
     36       <property name="verticalScrollBarPolicy">
     37        <enum>Qt::ScrollBarAlwaysOn</enum>
    3538       </property>
    3639      </widget>
  • src/mvc/delegate.cpp

    r5dbcd35 rbe12b9f  
    5252void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
    5353{
    54     if(!mViewPtr)
     54    if (!mViewPtr)
    5555        return;
    5656
    5757    painter->save();
    58     QColor bkgrColor = option.palette.color(QPalette::Background);
    59     //QColor bkgrColor = QColor(0xAA,0xAA,0xAA);
    60     QColor conflictColor = Qt::yellow;
    6158
    6259    QColor textColor = option.palette.color(QPalette::Text);
    63     QPen borderPen(textColor);
     60
    6461    if(hasParent(index))
    6562    {
     
    7067        int aux = option.rect.height() - SPACER - mControls[FavouriteControlOn]->image()->height();
    7168        Event *event = static_cast<Event*>(index.internalPointer());
     69
    7270        // font SMALL
    7371        QFont fontSmall = option.font;
     
    7876        QFont fontSmallB = fontSmall;
    7977        fontSmallB.setBold(true);
    80         QFontMetrics fmSmallB(fontSmallB);
    8178
    8279        // font BIG
     
    8582        fontBig.setPixelSize(aux*0.33);
    8683        QFontMetrics fmBig(fontBig);
     84
    8785        // font BIG bold
    8886        QFont fontBigB = fontBig;
     
    9088        QFontMetrics fmBigB(fontBigB);
    9189
    92         //int spacer = (fmSmall.boundingRect("999").width() < SPACER) ? SPACER : fmSmall.boundingRect("999").width();
    93 
    94         //Time conflicts are colored differently
    95         if(event->hasTimeConflict())
    96             bkgrColor = conflictColor;
    97 
    98         QLinearGradient itemGradient(option.rect.topLeft(), option.rect.bottomLeft());
    99         itemGradient.setColorAt(0.0, bkgrColor);
    100         itemGradient.setColorAt(1.0, bkgrColor);
    101 
    102         if(isLast(index))
    103         {
    104             QPainterPath endPath;
    105             endPath.moveTo(option.rect.topLeft());
    106             endPath.lineTo(option.rect.bottomLeft()-QPoint(0, RADIUS));
    107             endPath.arcTo(option.rect.left(), option.rect.bottom()-2*RADIUS, 2*RADIUS, 2*RADIUS, 180, 90);
    108             endPath.lineTo(option.rect.bottomRight()-QPoint(RADIUS, 0));
    109             endPath.arcTo(option.rect.right()-2*RADIUS, option.rect.bottom()-2*RADIUS, 2*RADIUS, 2*RADIUS, 270, 90);
    110             endPath.lineTo(option.rect.topRight());
    111 
    112             //painter->setBrush( bkgrColor );
    113             painter->setBrush(itemGradient);
    114             painter->setPen(Qt::NoPen);
    115             painter->drawPath(endPath);
    116             painter->setPen(borderPen);
    117 
    118             painter->setFont(option.font);
    119         }
    120         else // middle elements
    121         {
    122             //painter->setBrush( bkgrColor );
    123             painter->setBrush(itemGradient);
     90        // background (in case of time conflicts)
     91        if(event->hasTimeConflict()) {
     92            painter->setBrush(Qt::yellow);
    12493            painter->setPen(Qt::NoPen);
    12594            painter->drawRect(option.rect);
    126 
    127             painter->setPen(borderPen);
    128             /*
    129             // vertical lines
    130             painter->drawLine(option.rect.topLeft(), option.rect.bottomLeft());
    131             painter->drawLine(option.rect.topRight(), option.rect.bottomRight());
    132             */
    133             // horizontal lines
    134             painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
    135 
    136             painter->setFont(option.font);
     95        }
     96
     97        // background (without time conflicts)
     98        else {
     99            QStyleOption styleOption;
     100            styleOption.rect = option.rect;
     101            qApp->style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &styleOption, painter, mViewPtr);
    137102        }
    138103
     
    158123        // ("position of text" is lower-left angle of the first letter,
    159124        //  so the first line is actually at the same height as the image)
     125        painter->setPen(QPen(event->hasTimeConflict() ? Qt::black : textColor));
    160126        QPointF titlePointF(option.rect.x() + SPACER,
    161127                            option.rect.y() + SPACER + mControls[FavouriteControlOn]->image()->height());
     
    163129        painter->setFont(fontBig);
    164130        painter->drawText(titlePointF,start.toString("hh:mm") + "-" + start.addSecs(event->duration()).toString("hh:mm") + ", " + event->roomName());
     131
    165132        // title
    166133        titlePointF.setY(titlePointF.y()+fmBig.height()-fmBig.descent());
     
    182149        }
    183150        painter->drawText(titlePointF,title);
     151
    184152        // persons
    185153        titlePointF.setY(titlePointF.y()+fmSmall.height()-fmSmall.descent());
     
    187155        QString presenterPrefix = event->persons().count() < 2 ? "Presenter" : "Presenters";
    188156        painter->drawText(titlePointF,presenterPrefix + ": " + event->persons().join(" and "));
     157
    189158        // track
    190159        titlePointF.setY(titlePointF.y()+fmSmall.height()-fmSmall.descent());
    191160        painter->drawText(titlePointF,"Track: " + Track::retrieveTrackName(event->trackId()));
    192161    }
     162
    193163    else // doesn't have parent - time-groups' elements (top items)
    194164    {
     165        int numFav = numberOfFavourities(index);
     166
     167        QStyleOptionButton styleOptionButton;
     168        styleOptionButton.rect = option.rect;
     169        if (isExpanded(index)) styleOptionButton.state = QStyle::State_Sunken;
     170        // styleOptionButton.text = qVariantValue<QString>(index.data());
     171        qApp->style()->drawPrimitive(QStyle::PE_PanelButtonCommand, &styleOptionButton, painter, mViewPtr);
     172        // qApp->style()->drawControl(QStyle::CE_PushButtonLabel, &styleOptionButton, painter, mViewPtr);
     173        // qApp->style()->drawPrimitive(QStyle::PE_IndicatorArrowDown, &styleOptionButton, painter, mViewPtr);
     174
    195175        QFont fontSmall = option.font;
    196176        fontSmall.setBold(true);
     
    205185        int spacer = (fmSmall.boundingRect("999").width() < SPACER) ? SPACER : fmSmall.boundingRect("999").width();
    206186
    207         QLinearGradient titleGradient(option.rect.topLeft(), option.rect.topRight());
    208         bkgrColor = option.palette.color(QPalette::Highlight);
    209         textColor = option.palette.color(QPalette::HighlightedText);
    210         titleGradient.setColorAt(0.0, bkgrColor);
    211         titleGradient.setColorAt(1.0, bkgrColor);
    212 
    213         QPainterPath titlePath;
    214         if(isExpanded(index))
    215         {
    216             titlePath.moveTo(option.rect.bottomLeft());
    217             titlePath.lineTo(option.rect.topLeft()+QPoint(0, RADIUS));
    218             titlePath.arcTo(option.rect.left(), option.rect.top(), 2*RADIUS, 2*RADIUS, 180, -90);
    219             titlePath.lineTo(option.rect.topRight()-QPoint(RADIUS, 0));
    220             titlePath.arcTo(option.rect.right()-2*RADIUS, option.rect.top(), 2*RADIUS, 2*RADIUS, 90, -90);
    221             titlePath.lineTo(option.rect.bottomRight());
    222             titlePath.closeSubpath();
    223         }
    224         else
    225         {
    226             titlePath.lineTo(option.rect.topLeft()+QPoint(0, RADIUS));
    227             titlePath.arcTo(option.rect.left(), option.rect.top(), 2*RADIUS, 2*RADIUS, 180, -90);
    228             titlePath.lineTo(option.rect.topRight()-QPoint(RADIUS, 0));
    229             titlePath.arcTo(option.rect.right()-2*RADIUS, option.rect.top(), 2*RADIUS, 2*RADIUS, 90, -90);
    230             titlePath.lineTo(option.rect.bottomRight()-QPoint(0, RADIUS));
    231             titlePath.arcTo(option.rect.right()-2*RADIUS, option.rect.bottom()-2*RADIUS, 2*RADIUS, 2*RADIUS, 0, -90);
    232             titlePath.lineTo(option.rect.bottomLeft()+QPoint(RADIUS, 0));
    233             titlePath.arcTo(option.rect.left(), option.rect.bottom()-2*RADIUS, 2*RADIUS, 2*RADIUS, 270, -90);     
    234             titlePath.closeSubpath();
    235         }
    236 
    237         painter->setBrush(titleGradient);
    238         painter->setPen(borderPen);
    239         painter->drawPath(titlePath);
    240 
    241187        // draw icons
    242         borderPen.setColor(textColor);
    243         painter->setPen(borderPen);
     188        painter->setPen(QPen(textColor));
    244189        painter->setFont(fontSmall);
    245         QImage *image = mControls[FavouriteControlOn]->image();
     190        QImage *image = mControls[numFav ? FavouriteControlOn : FavouriteControlOff]->image();
    246191        QPoint drawPoint =
    247192            option.rect.topRight()
     
    251196        painter->drawImage(drawPoint,*image);
    252197        painter->drawText(drawPoint+QPoint(image->width()+2, image->height() - 2),
    253                 QString::number(numberOfFavourities(index)));
     198                QString::number(numFav));
    254199#ifdef MAEMO
    255200        drawPoint.setX(drawPoint.x() - spacer - image->width());
     
    268213                option.rect.y()+option.rect.height()-fmBig.descent());
    269214        painter->setFont(fontBig);
    270 
    271215        painter->drawText(titlePointF,qVariantValue<QString>(index.data()));
    272216    }
  • src/mvc/delegate.h

    r5dbcd35 rbe12b9f  
    2121#define DELEGATE_H
    2222
    23 #include <QItemDelegate>
    24 #include <QTreeView>
    25 #include <QPointer>
     23#include <QtGui>
    2624
    2725class Delegate : public QItemDelegate
Note: See TracChangeset for help on using the changeset viewer.