1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
13 File: YQPkgDescriptionDialog.cc
15 Author: Stefan Hundhammer <sh@suse.de>
17 Textdomain "packages-qt"
21 #define y2log_component "qt-pkg"
22 #include <ycp/y2log.h>
24 #include <QApplication>
25 #include <QDesktopWidget>
26 #include <QHBoxLayout>
28 #include <QPushButton>
34 #include "YQPkgDescriptionDialog.h"
35 #include "YQPkgDescriptionView.h"
36 #include "YQPkgList.h"
37 #include "QY2LayoutUtils.h"
42 #define SPACING 2 // between subwidgets
43 #define MARGIN 4 // around the widget
46 YQPkgDescriptionDialog::YQPkgDescriptionDialog( QWidget * parent, const QString & pkgName )
50 setWindowTitle( _( "Package Description" ) );
52 // Enable dialog resizing even without window manager
53 setSizeGripEnabled( true );
55 // Layout for the dialog (can't simply insert a QVBox)
57 QVBoxLayout * layout = new QVBoxLayout( this );
58 layout->setMargin(MARGIN);
59 layout->setSpacing(SPACING);
60 Q_CHECK_PTR( layout );
65 QSplitter * splitter = new QSplitter( Qt::Vertical, this );
66 Q_CHECK_PTR( splitter );
67 layout->addWidget( splitter );
71 _pkgList = new YQPkgList( splitter );
72 Q_CHECK_PTR( _pkgList );
73 _pkgList->resize( _pkgList->width(), 80 );
78 _pkgDescription = new YQPkgDescriptionView( splitter );
79 Q_CHECK_PTR( _pkgDescription );
80 _pkgDescription->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) ); // hor/vert
82 connect( _pkgList, SIGNAL( currentItemChanged ( ZyppSel ) ),
83 _pkgDescription, SLOT ( showDetailsIfVisible( ZyppSel ) ) );
86 // Button box (to center the single button)
88 QHBoxLayout * hbox = new QHBoxLayout( this );
90 hbox->setSpacing( SPACING );
91 hbox->setMargin ( MARGIN );
92 layout->addLayout( hbox );
96 QPushButton * button = new QPushButton( _( "&OK" ), this );
97 Q_CHECK_PTR( button );
98 hbox->addWidget(button);
99 button->setDefault( true );
101 connect( button, SIGNAL( clicked() ),
102 this, SLOT ( accept() ) );
112 YQPkgDescriptionDialog::filter( const QString & qPkgName )
114 std::string pkgName( qPrintable(qPkgName) );
115 YQUI::ui()->busyCursor();
119 // Search for pkgs with that name
121 for ( ZyppPoolIterator it = zyppPkgBegin();
125 ZyppObj zyppObj = (*it)->theObj();
127 if ( zyppObj && zyppObj->name() == pkgName )
128 _pkgList->addPkgItem( *it, tryCastToZyppPkg( zyppObj ) );
132 // Display description of the first pkg with that name
134 YQPkgObjListItem * firstItem = dynamic_cast<YQPkgObjListItem *> ( _pkgList->firstChild() );
137 _pkgDescription->showDetailsIfVisible( firstItem->selectable() );
139 _pkgDescription->clear();
142 YQUI::ui()->normalCursor();
147 YQPkgDescriptionDialog::isEmpty() const
150 return _pkgList->childCount() == 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"