Commit 99c83440 authored by Piotr Szymanski's avatar Piotr Szymanski

- notfinished indexing stuff from kchmpart

svn path=/trunk/playground/graphics/oKular/kpdf/; revision=485825
parent 5f647d31
/***************************************************************************
* Copyright (C) 2005 by Georgy Yunaev *
* tim@krasnogorsk.ru *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <qstringlist.h>
#include <qstyle.h>
#include "kchmtreeviewitem.h"
#include "xchmfile.h"
#include "iconstorage.h"
KCHMMainTreeViewItem::KCHMMainTreeViewItem( KListViewItem * parent, KListViewItem * after, QString name, QString aurl, int image) :
KListViewItem (parent, after, name), url(aurl), image_number(image)
{
}
KCHMMainTreeViewItem::KCHMMainTreeViewItem( KListView * parent, KListViewItem * after, QString name, QString aurl, int image) :
KListViewItem (parent, after, name), url(aurl), image_number(image)
{
}
const QPixmap * KCHMMainTreeViewItem::pixmap( int i ) const
{
int imagenum;
if ( i || image_number == KCHMImageType::IMAGE_NONE || image_number == KCHMImageType::IMAGE_INDEX )
return 0;
if ( firstChild () )
{
if ( isOpen() )
imagenum = (image_number == KCHMImageType::IMAGE_AUTO) ? 1 : image_number + 1;
else
imagenum = (image_number == KCHMImageType::IMAGE_AUTO) ? 0 : image_number;
}
else
imagenum = (image_number == KCHMImageType::IMAGE_AUTO) ? 10 : image_number;
return gIconStorage.getBookIconPixmap(imagenum);
}
QString KCHMMainTreeViewItem::getUrl( ) const
{
if ( url.find ('|') == -1 )
return url;
/*
// Create a dialog with URLs, and show it, so user can select an URL he/she wants.
QStringList urls = QStringList::split ('|', url);
QStringList titles;
CHMFile * xchm = (CHMFile *) ::mainWindow->getChmFile();
for ( unsigned int i = 0; i < urls.size(); i++ )
{
QString title = xchm->getTopicByUrl (urls[i]);
if ( !title )
{
qWarning ("Could not get item name for url '%s'", urls[i].ascii());
titles.push_back(QString::null);
}
else
titles.push_back(title);
}
KCHMDialogChooseUrlFromList dlg (urls, titles, ::mainWindow);
if ( dlg.exec() == QDialog::Accepted )
return dlg.getSelectedItemUrl();
*/
return QString::null;
}
void KCHMMainTreeViewItem::paintBranches( QPainter * p, const QColorGroup & cg, int w, int y, int h )
{
if ( image_number != KCHMImageType::IMAGE_INDEX )
KListViewItem::paintBranches(p, cg, w, y, h);
else
{
// Too bad that listView()->paintEmptyArea( p, QRect( 0, 0, w, h ) ) is protected.
// Taken from qt-x11-free-3.0.4/src/widgets/qlistview.cpp
QStyleOption opt( 0, 0 );
QStyle::SFlags how = QStyle::Style_Default | QStyle::Style_Enabled;
listView()->style().drawComplexControl( QStyle::CC_ListView,
p, listView(), QRect( 0, 0, w, h ), cg,
how, QStyle::SC_ListView, QStyle::SC_None,
opt );
}
}
void KCHMMainTreeViewItem::paintCell( QPainter * p, const QColorGroup & cg, int column, int width, int align )
{
QColorGroup newcg ( cg );
QColor c = newcg.text();
if ( url.find ('|') != -1 )
newcg.setColor( QColorGroup::Text, Qt::red );
else if ( url[0] == ':' )
newcg.setColor( QColorGroup::Text, Qt::lightGray );
else
{
KListViewItem::paintCell( p, cg, column, width, align );
return;
}
KListViewItem::paintCell( p, newcg, column, width, align );
newcg.setColor( QColorGroup::Text, c );
}
void KCHMMainTreeViewItem::setOpen( bool open )
{
if ( image_number != KCHMImageType::IMAGE_INDEX || open )
KListViewItem::setOpen (open);
}
/*
int KCHMMainTreeViewItem::width( const QFontMetrics & fm, const QListView * lv, int c ) const
{
return (QListViewItem::width
(QFontMetrics (myFont), lv, c));
}
*/
/***************************************************************************
* Copyright (C) 2005 by Georgy Yunaev *
* tim@krasnogorsk.ru *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef CTREEVIEWITEM_H
#define CTREEVIEWITEM_H
#include <klistview.h>
namespace KCHMImageType
{
const int IMAGE_NONE = -1;
const int IMAGE_AUTO = -2;
const int IMAGE_INDEX = -3;
};
/**
@author Georgy Yunaev
*/
class KCHMMainTreeViewItem : public KListViewItem
{
public:
KCHMMainTreeViewItem(KListViewItem* parent, KListViewItem* after, QString name, QString aurl, int image);
KCHMMainTreeViewItem(KListView* parent, KListViewItem* after, QString name, QString url, int image);
QString getUrl() const;
virtual void setOpen ( bool open );
private:
// virtual int width ( const QFontMetrics & fm, const KListView * lv, int c ) const;
virtual void paintBranches ( QPainter * p, const QColorGroup & cg, int w, int y, int h );
virtual void paintCell ( QPainter * p, const QColorGroup & cg, int column, int width, int align );
virtual const QPixmap * pixmap( int i ) const;
QString url;
int image_number;
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment