ginebra2/TitleUrlContainerSnippet.cpp
changeset 16 3c88a81ff781
parent 12 afcd8e6d025b
equal deleted inserted replaced
14:6aeb7a756187 16:3c88a81ff781
    32 
    32 
    33 #include "QGraphicsPixmapItem"
    33 #include "QGraphicsPixmapItem"
    34 
    34 
    35 #include "ChromeEffect.h"
    35 #include "ChromeEffect.h"
    36 
    36 
    37 #define BACKGROUND_GRADIENT_START "#232323"
    37 #define BACKGROUND_GRADIENT_START "#000000"
    38 #define BACKGROUND_GRADIENT_END "#000000"
    38 #define BACKGROUND_GRADIENT_END "#333333"
    39 
    39 
    40 #include <QDebug>
    40 #include <QDebug>
    41 
    41 
    42 namespace GVA {
    42 namespace GVA {
    43 
    43 
    47 
    47 
    48 TitleUrlContainerItem::TitleUrlContainerItem(ChromeSnippet * snippet, ChromeWidget * chrome, QGraphicsItem * parent)
    48 TitleUrlContainerItem::TitleUrlContainerItem(ChromeSnippet * snippet, ChromeWidget * chrome, QGraphicsItem * parent)
    49 : NativeChromeItem(snippet, parent)
    49 : NativeChromeItem(snippet, parent)
    50 , m_chrome(chrome)
    50 , m_chrome(chrome)
    51 {
    51 {
       
    52     setObjectName("TitleUrl");
    52     setProperties();    
    53     setProperties();    
    53     // Create the view port widget
    54     // Create the view port widget
    54     m_viewPort = new QGraphicsWidget(this);
    55     m_viewPort = new QGraphicsWidget(this);
    55     m_viewPort->setFlags(QGraphicsItem::ItemClipsChildrenToShape);
    56     m_viewPort->setFlags(QGraphicsItem::ItemClipsChildrenToShape);
    56     
    57     
    57     // Create title-url widget(still by the name UrlSearchItem)
    58     // Create title-url widget(still by the name UrlSearchItem)
    58     m_urlTileWidget = new GUrlSearchItem(snippet, chrome, m_viewPort); 
    59     m_urlTileWidget = new GUrlSearchItem(snippet, chrome, m_viewPort); 
    59 
    60 
    60     QPixmap dividerPixmap;
    61     QPixmap dividerPixmap;
    61     dividerPixmap.load(":/chrome/bedrockchrome/urlsearch.snippet/icons/URL_search_divider.png", "PNG");
    62     dividerPixmap.load(":/urlsearch/URL_search_divider.png", "PNG");
    62     m_dividerImage = new QGraphicsPixmapItem(dividerPixmap, m_viewPort);
    63     m_dividerImage = new QGraphicsPixmapItem(dividerPixmap, m_viewPort);
    63 
    64 
    64     QAction * backAction = new QAction(this);
    65     QAction * backAction = new QAction(this);
    65     connect(backAction, SIGNAL(triggered()), m_chrome, SIGNAL(goToBackground()));
    66     connect(backAction, SIGNAL(triggered()), m_chrome, SIGNAL(goToBackground()));
    66 
    67 	backAction->setObjectName("BackAction");
    67     m_backStepButton = new ActionButton(snippet, m_viewPort);
    68 
       
    69     m_backStepButton = new ActionButton(snippet, "BackStep", m_viewPort);
    68     m_backStepButton->setAction(backAction);
    70     m_backStepButton->setAction(backAction);
    69     m_backStepButton->setActiveOnPress(true);
    71     m_backStepButton->setActiveOnPress(true);
    70     m_backStepButton->addIcon(":/chrome/bedrockchrome/urlsearch.snippet/icons/backstep.png", QIcon::Normal);
    72     //m_backStepButton->addIcon(":/urlsearch/backstep.png", QIcon::Normal);
    71     m_backStepButton->addIcon(":/chrome/bedrockchrome/urlsearch.snippet/icons/backstep_pressed.png", QIcon::Active);
    73     m_backStepButton->addIcon(":/urlsearch/backstep_no_bg.png", QIcon::Normal);
       
    74     m_backStepButton->addIcon(":/urlsearch/backstep_pressed.png", QIcon::Active);
    72 
    75 
    73     // Monitor resize events.
    76     // Monitor resize events.
    74     safe_connect(m_chrome->renderer(), SIGNAL(chromeResized()), this, SLOT(onChromeResize()));
    77     safe_connect(m_chrome->renderer(), SIGNAL(chromeResized()), this, SLOT(onChromeResize()));
    75     safe_connect(m_urlTileWidget, SIGNAL(changeEditMode(bool)), this, SLOT(changeLayout(bool)));
    78     safe_connect(m_urlTileWidget, SIGNAL(changeEditMode(bool)), this, SLOT(changeLayout(bool)));
       
    79     safe_connect(m_urlTileWidget, SIGNAL(contextEvent(bool)), this, SIGNAL(contextEvent(bool)));
    76 }
    80 }
    77 
    81 
    78 TitleUrlContainerItem::~TitleUrlContainerItem()
    82 TitleUrlContainerItem::~TitleUrlContainerItem()
    79 {
    83 {
    80 
    84 
    81 }
    85 }
    82 
    86 
       
    87 void TitleUrlContainerItem::cut()
       
    88 {
       
    89     m_urlTileWidget->cut();
       
    90 }
       
    91 
       
    92 void TitleUrlContainerItem::copy()
       
    93 {
       
    94     m_urlTileWidget->copy();
       
    95 }
       
    96 
       
    97 void TitleUrlContainerItem::paste()
       
    98 {
       
    99     m_urlTileWidget->paste();
       
   100 }
       
   101 
       
   102 void TitleUrlContainerItem::setContextMenuStatus(bool on)
       
   103 { 
       
   104     m_urlTileWidget->setContextMenuStatus(on);
       
   105 }
       
   106 
    83 void TitleUrlContainerItem::setProperties() {
   107 void TitleUrlContainerItem::setProperties() {
    84 
       
    85   m_pen.setWidth(1);
       
    86   m_pen.setBrush(QBrush(QColor(Qt::black)));
       
    87 
       
    88   m_grad.setColorAt(0, BACKGROUND_GRADIENT_START);
   108   m_grad.setColorAt(0, BACKGROUND_GRADIENT_START);
    89   m_grad.setColorAt(1, BACKGROUND_GRADIENT_END);
   109   m_grad.setColorAt(1, BACKGROUND_GRADIENT_END);
    90 }
   110 }
    91 
   111 
    92 void TitleUrlContainerItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
   112 void TitleUrlContainerItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget){
    93 {
       
    94   Q_UNUSED(option)
   113   Q_UNUSED(option)
    95   Q_UNUSED(widget)
   114   Q_UNUSED(widget)
    96 
   115 
    97   painter->save();
   116   painter->save();
    98  
   117 
       
   118   qreal bounding_x = boundingRect().x();
       
   119   qreal bounding_y = boundingRect().y();
       
   120   qreal bounding_width = boundingRect().width();
       
   121   qreal bounding_height = boundingRect().height();
       
   122 
       
   123 
       
   124   // background
    99   painter->setRenderHint(QPainter::Antialiasing);
   125   painter->setRenderHint(QPainter::Antialiasing);
   100   painter->setPen(m_pen);
   126   painter->setPen(Qt::NoPen);
   101   if (snippet()->enabled()) {
   127   m_grad.setStart(bounding_x, bounding_y + bounding_height);
   102       painter->fillRect(boundingRect(), QBrush(m_grad));
   128   m_grad.setFinalStop(bounding_x, bounding_y);
   103   }
   129   painter->fillRect(boundingRect(), QBrush(m_grad));
   104   else {
       
   105       painter->fillRect(boundingRect(), QColor(Qt::gray));
       
   106       painter->setOpacity(ChromeEffect::disabledOpacity);
       
   107       painter->fillRect(boundingRect(), ChromeEffect::disabledColor);
       
   108   }
       
   109   
       
   110   // top border
   130   // top border
   111   painter->setPen(QPen(QColor(53,53,53)));
   131   painter->setPen(QPen(QColor(53,53,53)));
   112   painter->drawLine(boundingRect().x(), boundingRect().y(), boundingRect().x() + boundingRect().width(), boundingRect().y());
   132   painter->drawLine(bounding_x, bounding_y, bounding_x + bounding_width, bounding_y);
   113   // bottom border
   133   // bottom border
   114   painter->setPen(QPen(QColor(76,76,78)));
   134   painter->setPen(QPen(QColor(76,76,78)));
   115   painter->drawLine(boundingRect().x(), boundingRect().y() + boundingRect().height(), boundingRect().x() + boundingRect().width(), boundingRect().y() + boundingRect().height());
   135   painter->drawLine(bounding_x, bounding_y + bounding_height, bounding_x + bounding_width, bounding_y + bounding_height);
   116   // right border
   136   // right border
   117   painter->setPen(QPen(QColor(0,0,0)));
   137   painter->setPen(QPen(QColor(0,0,0)));
   118   painter->drawLine(boundingRect().x() + boundingRect().width(), boundingRect().y(), boundingRect().x() + boundingRect().width(), boundingRect().y() + boundingRect().height());
   138   painter->drawLine(bounding_x + bounding_width, bounding_y, bounding_x + bounding_width, bounding_y + bounding_height);
   119   // left border
   139   // left border
   120   painter->setPen(m_pen);
   140   painter->setPen(Qt::NoPen);
   121   QLinearGradient grad = QLinearGradient();
   141   QLinearGradient grad = QLinearGradient(bounding_x, bounding_y, bounding_x, bounding_y + bounding_height);
   122   grad.setColorAt(0, QColor(41,41,41));
   142   grad.setColorAt(0, QColor(41,41,41));
   123   grad.setColorAt(0.5, QColor(83,83,84));
   143   grad.setColorAt(0.5, QColor(83,83,84));
   124   grad.setColorAt(1, QColor(2,2,2));
   144   grad.setColorAt(1, QColor(2,2,2));
   125   painter->fillRect(QRect(boundingRect().x(), boundingRect().y(), 1, boundingRect().height()), QBrush(grad));
   145   painter->setBrush(QBrush(grad));
       
   146   painter->drawLine(bounding_x, bounding_y, bounding_x, bounding_y + bounding_height);
   126   
   147   
   127   painter->restore();
   148   painter->restore();
   128   
   149   
   129   NativeChromeItem::paint(painter, option, widget);
   150   NativeChromeItem::paint(painter, option, widget);
   130 }
   151 }
   134     QWebElement we = m_snippet->element();
   155     QWebElement we = m_snippet->element();
   135     QRectF g = we.geometry();
   156     QRectF g = we.geometry();
   136     QGraphicsWidget::resize(g.width(), g.height());
   157     QGraphicsWidget::resize(g.width(), g.height());
   137 }
   158 }
   138 
   159 
   139 void TitleUrlContainerItem::resizeEvent(QGraphicsSceneResizeEvent * event)
   160 void TitleUrlContainerItem::resizeEvent(QGraphicsSceneResizeEvent * event){
   140 {
       
   141     QSizeF size = event->newSize();
   161     QSizeF size = event->newSize();
   142 
   162 
   143     qreal width = size.width();
   163     qreal width = size.width();
   144     qreal height = size.height();
   164     qreal height = size.height();
   145 
   165 
   149             width,
   169             width,
   150             height);
   170             height);
   151 
   171 
   152     m_backStepButton->setGeometry(
   172     m_backStepButton->setGeometry(
   153                 width - ICONWIDTH, 
   173                 width - ICONWIDTH, 
   154                 (height - ICONHEIGHT)/2,
   174                 0,
   155                 ICONWIDTH,
   175                 ICONWIDTH,
   156                 ICONHEIGHT);
   176                 height);
   157 
   177 
   158     // When we first get resize event, the widget is not yet set to visible by
   178     // When we first get resize event, the widget is not yet set to visible by
   159     // Ginebra. If the widget is not visible and for later resize events, if back-step
   179     // Ginebra. If the widget is not visible and for later resize events, if back-step
   160     // button is visible, set the width of url-title widget taking into account
   180     // button is visible, set the width of url-title widget taking into account
   161     // the width of back-step button
   181     // the width of back-step button
   213 }
   233 }
   214 
   234 
   215 TitleUrlContainerSnippet * TitleUrlContainerSnippet::instance(const QString& elementId, ChromeWidget * chrome, const QWebElement & element)
   235 TitleUrlContainerSnippet * TitleUrlContainerSnippet::instance(const QString& elementId, ChromeWidget * chrome, const QWebElement & element)
   216 {
   236 {
   217     TitleUrlContainerSnippet * that = new TitleUrlContainerSnippet( elementId, chrome, 0, element );
   237     TitleUrlContainerSnippet * that = new TitleUrlContainerSnippet( elementId, chrome, 0, element );
   218     that->setChromeWidget( new TitleUrlContainerItem(that, chrome));
   238     TitleUrlContainerItem * titleUrlContainerItem = new TitleUrlContainerItem(that, chrome);
   219 
   239     safe_connect(titleUrlContainerItem, SIGNAL(contextEvent(bool)), that, SLOT(sendContextMenuEvent(bool)));
       
   240     that->setChromeWidget(titleUrlContainerItem);
   220     return that;
   241     return that;
   221 }
   242 }
   222 
   243 
   223 QString TitleUrlContainerSnippet::url() const
   244 QString TitleUrlContainerSnippet::url() const
   224 {
   245 {
   226     
   247     
   227     urlContainer = dynamic_cast<TitleUrlContainerItem const *> (constWidget());
   248     urlContainer = dynamic_cast<TitleUrlContainerItem const *> (constWidget());
   228     return urlContainer->url();
   249     return urlContainer->url();
   229 }
   250 }
   230 
   251 
       
   252 void TitleUrlContainerSnippet::sendContextMenuEvent(bool isContentSelected)
       
   253 {
       
   254     emit contextEvent(isContentSelected, elementId());     
       
   255 }
       
   256 
   231 } // end of namespace GVA
   257 } // end of namespace GVA
   232 
   258 
   233 
   259 
   234 
   260