1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
13 File: YQPkgDescriptionDialog.cc
15 Author: Stefan Hundhammer <sh@suse.de>
17 Textdomain "packages-qt"
23 #define y2log_component "qt-pkg"
24 #include <ycp/y2log.h>
26 #include <qapplication.h>
27 #include <qdesktopwidget.h>
31 #include <qpushbutton.h>
32 #include <qsplitter.h>
34 #include <q3valuelist.h>
36 #include <q3boxlayout.h>
38 #include "YQPkgDescriptionDialog.h"
39 #include "YQPkgDescriptionView.h"
40 #include "YQPkgList.h"
41 #include "QY2LayoutUtils.h"
46 #define SPACING 2 // between subwidgets
47 #define MARGIN 4 // around the widget
50 YQPkgDescriptionDialog::YQPkgDescriptionDialog( QWidget * parent, const QString & pkgName )
54 setCaption( _( "Package Description" ) );
56 // Enable dialog resizing even without window manager
57 setSizeGripEnabled( true );
59 // Layout for the dialog (can't simply insert a QVBox)
61 Q3VBoxLayout * layout = new Q3VBoxLayout( this, MARGIN, SPACING );
62 Q_CHECK_PTR( layout );
67 QSplitter * splitter = new QSplitter( Qt::Vertical, this );
68 Q_CHECK_PTR( splitter );
69 layout->addWidget( splitter );
70 splitter->setMargin( MARGIN );
75 _pkgList = new YQPkgList( splitter );
76 Q_CHECK_PTR( _pkgList );
77 _pkgList->resize( _pkgList->width(), 80 );
82 _pkgDescription = new YQPkgDescriptionView( splitter );
83 Q_CHECK_PTR( _pkgDescription );
84 _pkgDescription->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) ); // hor/vert
86 connect( _pkgList, SIGNAL( currentItemChanged ( ZyppSel ) ),
87 _pkgDescription, SLOT ( showDetailsIfVisible( ZyppSel ) ) );
90 // Button box (to center the single button)
92 Q3HBox * hbox = new Q3HBox( this );
94 hbox->setSpacing( SPACING );
95 hbox->setMargin ( MARGIN );
96 layout->addWidget( hbox );
103 QPushButton * button = new QPushButton( _( "&OK" ), hbox );
104 Q_CHECK_PTR( button );
105 button->setDefault( true );
107 connect( button, SIGNAL( clicked() ),
108 this, SLOT ( accept() ) );
118 YQPkgDescriptionDialog::filter( const QString & qPkgName )
120 std::string pkgName( (const char *) qPkgName );
121 YQUI::ui()->busyCursor();
125 // Search for pkgs with that name
127 for ( ZyppPoolIterator it = zyppPkgBegin();
131 ZyppObj zyppObj = (*it)->theObj();
133 if ( zyppObj && zyppObj->name() == pkgName )
134 _pkgList->addPkgItem( *it, tryCastToZyppPkg( zyppObj ) );
138 // Display description of the first pkg with that name
140 YQPkgObjListItem * firstItem = dynamic_cast<YQPkgObjListItem *> ( _pkgList->firstChild() );
143 _pkgDescription->showDetailsIfVisible( firstItem->selectable() );
145 _pkgDescription->clear();
148 YQUI::ui()->normalCursor();
153 YQPkgDescriptionDialog::isEmpty() const
156 return _pkgList->childCount() == 0;
164 YQPkgDescriptionDialog::sizeHint() const
166 QRect available = qApp->desktop()->availableGeometry( (QWidget *) this );
167 QSize size = QDialog::sizeHint();
168 size = size.boundedTo( QSize( available.width(), available.height() ) );
175 YQPkgDescriptionDialog::showDescriptionDialog( const QString & pkgName )
177 YQPkgDescriptionDialog dialog( 0, pkgName );
184 #include "YQPkgDescriptionDialog.moc"