Back to index

scribus-ng  1.3.4.dfsg+svn20071115
dynamictip.cpp
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 /***************************************************************************
00008                           dynamictip.cpp  -  description
00009                              -------------------
00010     begin                : Wed Aug 31 2005
00011     copyright            : (C) 2005 by Franz Schmid
00012     email                : Franz.Schmid@altmuehlnet.de
00013  ***************************************************************************/
00014 
00015 /***************************************************************************
00016  *                                                                         *
00017  *   This program is free software; you can redistribute it and/or modify  *
00018  *   it under the terms of the GNU General Public License as published by  *
00019  *   the Free Software Foundation; either version 2 of the License, or     *
00020  *   (at your option) any later version.                                   *
00021  *                                                                         *
00022  ***************************************************************************/
00023 
00024 #include "dynamictip.h"
00025 #include "seiten.h"
00026 #include "tree.h"
00027 #include "pageitem.h"
00028 
00029 DynamicTip::DynamicTip( QListBox* parent, ColorList* pale ) : QToolTip( parent )
00030 {
00031        colorList = pale;
00032        listB = parent;
00033        kind = ColorListBox;
00034 }
00035 
00036 DynamicTip::DynamicTip( QTable* parent ) : QToolTip( parent->viewport() )
00037 {
00038        table = parent;
00039        kind = Table;
00040 }
00041 
00042 DynamicTip::DynamicTip( QHeader *parent ) : QToolTip( parent )
00043 {
00044        header = parent;
00045        kind = TableHeader;
00046 }
00047 
00048 DynamicTip::DynamicTip( QListView* parent ) : QToolTip( parent->viewport() )
00049 {
00050        listV = parent;
00051        kind = TreeView;
00052 }
00053 
00054 void DynamicTip::maybeTip( const QPoint &pos )
00055 {
00056        if (kind == ColorListBox)
00057        {
00058               QListBoxItem* it = listB->itemAt(pos);
00059               if (it != 0)
00060               {
00061                      if (!colorList->contains(it->text()))
00062                             return;
00063                      QString tipText = "";
00064                      ScColor col = (*colorList)[it->text()];
00065                      if (col.getColorModel() == colorModelCMYK)
00066                      {
00067                             int c, m, y, k;
00068                             col.getCMYK(&c, &m, &y, &k);
00069                             tipText = QString("C:%1% M:%2% Y:%3% K:%4%").arg(qRound(c / 2.55)).arg(qRound(m / 2.55)).arg(qRound(y / 2.55)).arg(qRound(k / 2.55));
00070                      }
00071                      else
00072                      {
00073                             int r, g, b;
00074                             col.getRawRGBColor(&r, &g, &b);
00075                             tipText = QString("R:%1 G:%2 B:%3").arg(r).arg(g).arg(b);
00076                      }
00077                      tip(listB->itemRect(it), tipText);
00078               }
00079        }
00080        else if (kind == Table)
00081        {
00082               QPoint cp = table->viewportToContents( pos );
00083               int row = table->rowAt( cp.y() );
00084               int col = table->columnAt( cp.x() );
00085               QTableItem* ite = table->item(row, col);
00086               if (ite == 0)
00087                      return;
00088               QRect cr = table->cellGeometry( row, col );
00089               cr.moveTopLeft( table->contentsToViewport( cr.topLeft() ) );
00090               SeItem* it = (SeItem*)ite;
00091               QString tipString = it->getPageName();
00092               tip( cr, tipString );
00093        }
00094        else if (kind == TableHeader)
00095        {
00096               int col = header->sectionAt(pos.x());
00097               tip( header->sectionRect(col), headerTips[col] );
00098        }
00099        else if (kind == TreeView)
00100        {
00101               QListViewItem* it = listV->itemAt(pos);
00102               if (it != 0)
00103               {
00104                      TreeItem *item = (TreeItem*)it;
00105                      if (item != NULL)
00106                      {
00107                             QString tipText = "";
00108                             if ((item->type == 1) || (item->type == 3) || (item->type == 4))
00109                             {
00110                                    PageItem *pgItem = item->PageItemObject;
00111                                    switch (pgItem->itemType())
00112                                    {
00113                                           case PageItem::ImageFrame:
00114                                                  tipText = QObject::tr("Image");
00115                                                  break;
00116                                           case PageItem::TextFrame:
00117                                                  switch (pgItem->annotation().Type())
00118                                                  {
00119                                                         case 2:
00120                                                                tipText = QObject::tr("PDF Push Button");
00121                                                                break;
00122                                                         case 3:
00123                                                                tipText = QObject::tr("PDF Text Field");
00124                                                                break;
00125                                                         case 4:
00126                                                                tipText = QObject::tr("PDF Check Box");
00127                                                                break;
00128                                                         case 5:
00129                                                                tipText = QObject::tr("PDF Combo Box");
00130                                                                break;
00131                                                         case 6:
00132                                                                tipText = QObject::tr("PDF List Box");
00133                                                                break;
00134                                                         case 10:
00135                                                                tipText = QObject::tr("PDF Text Annotation");
00136                                                                break;
00137                                                         case 11:
00138                                                                tipText = QObject::tr("PDF Link Annotation");
00139                                                                break;
00140                                                         default:
00141                                                                tipText = QObject::tr("Text");
00142                                                                break;
00143                                                  }
00144                                                  break;
00145                                           case PageItem::Line:
00146                                                  tipText = QObject::tr("Line");
00147                                                  break;
00148                                           case PageItem::Polygon:
00149                                                  tipText = QObject::tr("Polygon");
00150                                                  break;
00151                                           case PageItem::PolyLine:
00152                                                  tipText = QObject::tr("Polyline");
00153                                                  break;
00154                                           case PageItem::PathText:
00155                                                  tipText = QObject::tr("PathText");
00156                                                  break;
00157                                           default:
00158                                                  break;
00159                                    }
00160                                    tip(listV->itemRect(it), tipText);
00161                             }
00162                      }
00163               }
00164        }
00165 }
00166 
00167 void DynamicTip::addHeaderTip( QString tip )
00168 {
00169        headerTips.append(tip);
00170 }
00171 
00172 void DynamicTip::clearHeaderTips()
00173 {
00174        headerTips.clear();
00175 }