00001 #include <qptrvector.h>
00002 #include <qstring.h>
00003 #include "widget.h"
00004 #include "widget_moc.h"
00005 #include <iostream.h>
00006
00007 Listing::Listing( QWidget *parent, const char *name, WFlags f ) : QListView( parent, name, f )
00008 {
00009
00010 addColumn( "Classes" );
00011 QPtrVector<QString> qpv_Classes;
00012 QPtrVector<QString> qpv_Software;
00013 QListViewItem *qlvi_Class;
00014 QListViewItem *qlvi_Software;
00015 database db;
00016 int x = 0;
00017 int y = 0;
00018
00019 qpv_Classes = db.get_all_classes();
00020 for( x = 0; x < qpv_Classes.size(); x++ )
00021 {
00022 qlvi_Class = new QListViewItem( this, *(qpv_Classes[x]) );
00023 qpv_Software = db.get_all_software( *(qpv_Classes[x]) );
00024 for( y = 0; y < qpv_Software.size(); y++ )
00025 {
00026 qlvi_Software = new QListViewItem( qlvi_Class, *(qpv_Software[y]) );
00027 }
00028 }
00029 setRootIsDecorated(true);
00030 }
00031
00032
00033 TextView::TextView( QWidget *parent, const char *name ) : QTextEdit( parent, name )
00034 {
00035 setReadOnly( true );
00036 }
00037 void TextView::showInfo( QListViewItem *qlvi_Item )
00038 {
00039 database db;
00040 QPtrVector<QString> qpv_Info(0);
00041 QString qs_Text("");
00042 int x = 0;
00043
00044 qpv_Info = db.get_software( qlvi_Item->text(0) );
00045 if( !(qpv_Info.size() < 1) )
00046 {
00047 if( "" == *(qpv_Info[0]) )
00048 {
00049
00050 qpv_Info = db.get_class( qlvi_Item->text(0) );
00051 qs_Text = "Name: " + *(qpv_Info[0]) + "\nSoftware for this course:";
00052 for( x = 1; x<qpv_Info.size(); x++ )
00053 qs_Text += "\n" + *(qpv_Info[x]);
00054 } else {
00055 qs_Text = "Name: " + *(qpv_Info[1]) + "\nPackage: " + *(qpv_Info[0]) + "\nVersion: " + *(qpv_Info[2]) + "\nDownload from: " + *(qpv_Info[4]) + "\nDescription: " + *(qpv_Info[3]);
00056 }
00057 }
00058 setText( qs_Text );
00059 }
00060
00061
00062 SearchButtons::SearchButtons( QWidget *parent, const char *name, const char *searchName, const char *searchAgainName ) : QHBox( parent, name )
00063 {
00064 qpb_Search = new QPushButton( "Search", this, searchName );
00065 qpb_SearchAgain = new QPushButton( "Search Again", this, searchAgainName );
00066 }
00067
00068 SearchInput::SearchInput( QWidget *parent, const char *name, const char *labelName, const char *lineEditName, const char *labelText ) : QHBox( parent, name )
00069 {
00070 ql_Label = new QLabel( labelText, this, labelName );
00071 qle_Edit = new QLineEdit( this, lineEditName );
00072 }
00073
00074
00075 SearchBox::SearchBox( QWidget *parent, const char *name ) : QVBox( parent, name )
00076 {
00077 si_Class = new SearchInput( this, "search_input_class", "label_class", "line_edit_class", "Class:" );
00078 sbs_Class = new SearchButtons( this, "search_class_buttons", "search_for_class", "search_again_for_class" );
00079
00080
00081 }
00082
00083
00084 RightBox::RightBox( QWidget *parent, const char *name ) : QVBox( parent, name )
00085 {
00086 tv_Text = new TextView( this, "text" );
00087 sb_Search = new SearchBox( this, "search" );
00088 }
00089
00090
00091 MainLayout::MainLayout( QWidget *parent, const char *name ) : QHBox( parent, name )
00092 {
00093 l_List = new Listing( this, "list" );
00094 rv_Box = new RightBox( this, "rightbox" );
00095
00096
00097
00098
00099 connect( l_List, SIGNAL(selectionChanged(QListViewItem*)), rv_Box->tv_Text, SLOT(showInfo(QListViewItem*)) );
00100
00101 connect( rv_Box->sb_Search->sbs_Class->qpb_Search, SIGNAL(clicked()), this, SLOT(searchClass()) );
00102
00103 connect( rv_Box->sb_Search->sbs_Class->qpb_SearchAgain, SIGNAL(clicked()), this, SLOT(searchClassAgain()) );
00104
00105
00106
00107
00108 }
00109 void MainLayout::searchClass()
00110 {
00111 QString qs_Term( "" );
00112 QListViewItem *qlvi_Result;
00113
00114 qs_Term = rv_Box->sb_Search->si_Class->qle_Edit->text();
00115
00116 qlvi_Result = l_List->findItem( qs_Term, 0, Qt::Contains );
00117 l_List->setSelected( qlvi_Result, true );
00118 l_List->ensureItemVisible( qlvi_Result );
00119 }
00120 void MainLayout::searchClassAgain()
00121 {
00122
00123 }