Changeset 14457


Ignore:
Timestamp:
Jan 20, 2015, 11:28:38 PM (6 years ago)
Author:
mikedld
Message:

Improve tracker list look (torrent properties dialog), support RTL layout

Location:
trunk/qt
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/qt/details.ui

    r14397 r14457  
    525525       <item row="0" column="0" rowspan="4">
    526526        <widget class="QListView" name="trackersView">
     527         <property name="horizontalScrollBarPolicy">
     528          <enum>Qt::ScrollBarAlwaysOff</enum>
     529         </property>
    527530         <property name="alternatingRowColors">
    528531          <bool>true</bool>
  • trunk/qt/favicon.cc

    r14445 r14457  
    8989}
    9090
     91QSize
     92Favicons::getIconSize ()
     93{
     94  return QSize (16, 16);
     95}
     96
    9197QPixmap
    9298Favicons::find (const QUrl& url)
     
    94100  return findFromHost (getHost (url));
    95101}
    96 
    97 namespace
    98 {
    99   const QSize rightSize (16, 16);
    100 };
    101102
    102103QPixmap
     
    106107
    107108  const QPixmap pixmap = myPixmaps[host];
     109  const QSize rightSize = getIconSize ();
    108110  return pixmap.isNull () || pixmap.size () == rightSize ? pixmap : pixmap.scaled (rightSize);
    109111}
  • trunk/qt/favicon.h

    r14370 r14457  
    2727
    2828    static QString getHost( const QUrl& url );
     29    static QSize getIconSize ();
    2930
    3031  public:
  • trunk/qt/tracker-delegate.cc

    r14456 r14457  
    1010#include <iostream>
    1111
     12#include <QAbstractTextDocumentLayout>
     13#include <QApplication>
    1214#include <QPainter>
    1315#include <QPixmap>
     
    2224#include "tracker-delegate.h"
    2325#include "tracker-model.h"
     26#include "utils.h"
    2427
    2528/***
     
    3033{
    3134  const int mySpacing = 6;
    32   const QSize myMargin (10, 6);
     35  const QSize myMargin (10, 10);
     36
     37  class ItemLayout
     38  {
     39    private:
     40      QTextDocument myTextDocument;
     41
     42    public:
     43      QRect iconRect;
     44      QRect textRect;
     45
     46    public:
     47      ItemLayout(const QString& text, bool suppressColors, Qt::LayoutDirection direction,
     48                 const QPoint& topLeft, int width);
     49
     50      QSize size () const
     51      {
     52        return (iconRect | textRect).size ();
     53      }
     54
     55      QAbstractTextDocumentLayout * textLayout () const
     56      {
     57        return myTextDocument.documentLayout ();
     58      }
     59  };
     60
     61  ItemLayout::ItemLayout(const QString& text, bool suppressColors, Qt::LayoutDirection direction,
     62                         const QPoint& topLeft, int width)
     63  {
     64    const QStyle * style (qApp->style ());
     65    const QSize iconSize = Favicons::getIconSize ();
     66
     67    QRect baseRect (topLeft, QSize (width, 0));
     68
     69    iconRect = style->alignedRect (direction, Qt::AlignLeft | Qt::AlignTop, iconSize, baseRect);
     70    Utils::narrowRect (baseRect, iconSize.width () + mySpacing, 0, direction);
     71
     72    myTextDocument.setDocumentMargin (0);
     73    myTextDocument.setTextWidth (baseRect.width ());
     74    QTextOption textOption;
     75    textOption.setTextDirection (direction);
     76    if (suppressColors)
     77      textOption.setFlags (QTextOption::SuppressColors);
     78    myTextDocument.setDefaultTextOption (textOption);
     79    myTextDocument.setHtml (text);
     80
     81    textRect = baseRect;
     82    textRect.setSize (myTextDocument.size ().toSize ());
     83  }
    3384}
    3485
     
    49100                           const TrackerInfo          & info) const
    50101{
    51   Q_UNUSED (option);
    52 
    53   QPixmap favicon = info.st.getFavicon ();
    54 
    55   const QString text = TrackerDelegate::getText(info);
    56   QTextDocument textDoc;
    57   textDoc.setHtml (text);
    58   const QSize textSize = textDoc.size().toSize();
    59 
    60   return QSize (myMargin.width() + favicon.width() + mySpacing + textSize.width() + myMargin.width(),
    61                 myMargin.height() + qMax<int> (favicon.height(), textSize.height()) + myMargin.height());
     102  const ItemLayout layout (getText (info), true, option.direction, QPoint (0, 0), option.rect.width () - myMargin.width () * 2);
     103  return layout.size () + myMargin * 2;
    62104}
    63105
     
    89131                              const TrackerInfo           & inf) const
    90132{
     133  const bool isItemSelected ((option.state & QStyle::State_Selected) != 0);
     134
     135  QIcon trackerIcon (inf.st.getFavicon());
     136
     137  const QRect contentRect (option.rect.adjusted (myMargin.width (), myMargin.height (), -myMargin.width (), -myMargin.height ()));
     138  const ItemLayout layout (getText (inf), isItemSelected, option.direction, contentRect.topLeft (), contentRect.width ());
     139
    91140  painter->save();
    92141
    93   QPixmap icon = inf.st.getFavicon();
    94   QRect iconArea (option.rect.x() + myMargin.width(),
    95                   option.rect.y() + myMargin.height(),
    96                   icon.width(),
    97                   icon.height());
    98   painter->drawPixmap (iconArea.x(), iconArea.y()+4, icon);
    99 
    100   const int textWidth = option.rect.width() - myMargin.width()*2 - mySpacing - icon.width();
    101   const int textX = myMargin.width() + icon.width() + mySpacing;
    102   const QString text = getText (inf);
    103   QTextDocument textDoc;
    104   textDoc.setHtml (text);
    105   const QRect textRect (textX, iconArea.y(), textWidth, option.rect.height() - myMargin.height()*2);
    106   painter->translate (textRect.topLeft());
    107   textDoc.drawContents (painter, textRect.translated (-textRect.topLeft()));
     142  trackerIcon.paint (painter, layout.iconRect, Qt::AlignCenter, isItemSelected ? QIcon::Selected : QIcon::Normal, QIcon::On);
     143
     144  QAbstractTextDocumentLayout::PaintContext paintContext;
     145  paintContext.clip = layout.textRect.translated (-layout.textRect.topLeft ());
     146  paintContext.palette.setColor (QPalette::Text, option.palette.color (isItemSelected ? QPalette::HighlightedText : QPalette::Text));
     147  painter->translate (layout.textRect.topLeft());
     148  layout.textLayout ()->draw (painter, paintContext);
    108149
    109150  painter->restore();
Note: See TracChangeset for help on using the changeset viewer.