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();
58 Q_CHECK_PTR( layout );
60 layout->setMargin(MARGIN);
61 layout->setSpacing(SPACING);
67 QSplitter * splitter = new QSplitter( Qt::Vertical, this );
68 Q_CHECK_PTR( splitter );
69 layout->addWidget( splitter );
73 _pkgList = new YQPkgList( splitter );
74 Q_CHECK_PTR( _pkgList );
75 _pkgList->resize( _pkgList->width(), 80 );
80 _pkgDescription = new YQPkgDescriptionView( splitter );
81 Q_CHECK_PTR( _pkgDescription );
82 _pkgDescription->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) ); // hor/vert
84 connect( _pkgList, SIGNAL( currentItemChanged ( ZyppSel ) ),
85 _pkgDescription, SLOT ( showDetailsIfVisible( ZyppSel ) ) );
88 // Button box (to center the single button)
90 QHBoxLayout * hbox = new QHBoxLayout();
92 hbox->setSpacing( SPACING );
93 hbox->setMargin ( MARGIN );
94 layout->addLayout( hbox );
98 QPushButton * button = new QPushButton( _( "&OK" ), this );
99 Q_CHECK_PTR( button );
100 hbox->addWidget(button);
101 button->setDefault( true );
103 connect( button, SIGNAL( clicked() ),
104 this, SLOT ( accept() ) );
114 YQPkgDescriptionDialog::filter( const QString & qPkgName )
116 std::string pkgName( qPrintable(qPkgName) );
117 YQUI::ui()->busyCursor();
121 // Search for pkgs with that name
123 for ( ZyppPoolIterator it = zyppPkgBegin();
127 ZyppObj zyppObj = (*it)->theObj();
129 if ( zyppObj && zyppObj->name() == pkgName )
130 _pkgList->addPkgItem( *it, tryCastToZyppPkg( zyppObj ) );
134 // Display description of the first pkg with that name
136 YQPkgObjListItem * firstItem = dynamic_cast<YQPkgObjListItem *> ( _pkgList->firstChild() );
139 _pkgDescription->showDetailsIfVisible( firstItem->selectable() );
141 _pkgDescription->clear();
144 YQUI::ui()->normalCursor();
149 YQPkgDescriptionDialog::isEmpty() const
152 return _pkgList->childCount() == 0;
160 YQPkgDescriptionDialog::sizeHint() const
162 QRect available = qApp->desktop()->availableGeometry( (QWidget *) this );
163 QSize size = QDialog::sizeHint();
164 size = size.boundedTo( QSize( available.width(), available.height() ) );
171 YQPkgDescriptionDialog::showDescriptionDialog( const QString & pkgName )
173 YQPkgDescriptionDialog dialog( 0, pkgName );
180 #include "YQPkgDescriptionDialog.moc"