1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
13 File: YQPkgDescriptionDialog.cc
15 Author: Stefan Hundhammer <sh@suse.de>
17 Textdomain "packages-qt"
22 #define y2log_component "qt-pkg"
23 #include <ycp/y2log.h>
25 #include <qapplication.h>
26 #include <qdesktopwidget.h>
30 #include <qpushbutton.h>
31 #include <qsplitter.h>
33 #include <q3valuelist.h>
35 #include <q3boxlayout.h>
37 #include "YQPkgDescriptionDialog.h"
38 #include "YQPkgDescriptionView.h"
39 #include "YQPkgList.h"
40 #include "QY2LayoutUtils.h"
45 #define SPACING 2 // between subwidgets
46 #define MARGIN 4 // around the widget
49 YQPkgDescriptionDialog::YQPkgDescriptionDialog( QWidget * parent, const QString & pkgName )
53 setCaption( _( "Package Description" ) );
55 // Enable dialog resizing even without window manager
56 setSizeGripEnabled( true );
58 // Layout for the dialog (can't simply insert a QVBox)
60 Q3VBoxLayout * layout = new Q3VBoxLayout( this, MARGIN, SPACING );
61 Q_CHECK_PTR( layout );
66 QSplitter * splitter = new QSplitter( Qt::Vertical, this );
67 Q_CHECK_PTR( splitter );
68 layout->addWidget( splitter );
69 splitter->setMargin( MARGIN );
74 _pkgList = new YQPkgList( splitter );
75 Q_CHECK_PTR( _pkgList );
76 _pkgList->resize( _pkgList->width(), 80 );
81 _pkgDescription = new YQPkgDescriptionView( splitter );
82 Q_CHECK_PTR( _pkgDescription );
83 _pkgDescription->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) ); // hor/vert
85 connect( _pkgList, SIGNAL( selectionChanged ( ZyppSel ) ),
86 _pkgDescription, SLOT ( showDetailsIfVisible( ZyppSel ) ) );
89 // Button box (to center the single button)
91 Q3HBox * hbox = new Q3HBox( this );
93 hbox->setSpacing( SPACING );
94 hbox->setMargin ( MARGIN );
95 layout->addWidget( hbox );
102 QPushButton * button = new QPushButton( _( "&OK" ), hbox );
103 Q_CHECK_PTR( button );
104 button->setDefault( true );
106 connect( button, SIGNAL( clicked() ),
107 this, SLOT ( accept() ) );
117 YQPkgDescriptionDialog::filter( const QString & qPkgName )
119 std::string pkgName( (const char *) qPkgName );
120 YQUI::ui()->busyCursor();
124 // Search for pkgs with that name
126 for ( ZyppPoolIterator it = zyppPkgBegin();
130 ZyppObj zyppObj = (*it)->theObj();
132 if ( zyppObj && zyppObj->name() == pkgName )
133 _pkgList->addPkgItem( *it, tryCastToZyppPkg( zyppObj ) );
137 // Display description of the first pkg with that name
139 YQPkgObjListItem * firstItem = dynamic_cast<YQPkgObjListItem *> ( _pkgList->firstChild() );
142 _pkgDescription->showDetailsIfVisible( firstItem->selectable() );
144 _pkgDescription->clear();
146 YQUI::ui()->normalCursor();
151 YQPkgDescriptionDialog::isEmpty() const
153 return _pkgList->firstChild() == 0;
158 YQPkgDescriptionDialog::sizeHint() const
160 QRect available = qApp->desktop()->availableGeometry( (QWidget *) this );
161 QSize size = QDialog::sizeHint();
162 size = size.boundedTo( QSize( available.width(), available.height() ) );
169 YQPkgDescriptionDialog::showDescriptionDialog( const QString & pkgName )
171 YQPkgDescriptionDialog dialog( 0, pkgName );
178 #include "YQPkgDescriptionDialog.moc"