#include <qfiledialog.h>
#include <qlistview.h>
#include <qstring.h>
#include <qfile.h>
#include <qfileinfo.h>
#include <qstringlist.h>
#include<qmessagebox.h>
#include <qpixmap.h>
#include <qdir.h>
#include <qstringlist.h>
void Form1::init()
{
listView->setColumnWidth(1,0);
listView->header()->setResizeEnabled(false,1);
}
void Form1::fileOpen()
{
QListViewItem* root=new QListViewItem(listView);
"/home/",
this,
"get existing directory",
"Choose a directory",
TRUE );
root->setText(0,m_source);
CreateDirTree(root,m_source);
init();
}
void Form1
::CreateDirTree(QListViewItem
*item,
QString path
) {
const QFileInfoList * dirs=dir.entryInfoList();
{
if(dirs)
{
QFileInfoListIterator it(*dirs);
while(fileInfo=it.current())
{
++it;
if(fileInfo->fileName() =="." || fileInfo->fileName() =="..")
;
else if (fileInfo->isDir())
{
FilePath =path +"/"+ fileInfo->fileName();
m_temp = new QListViewItem(item);
m_temp->setText(0,fileInfo->fileName());
m_temp
->setPixmap
(0,
QPixmap("/root/qt/Tree/images/folderunchecked.png"));
CreateDirTree(m_temp,FilePath);
}
else
{
m_temp = new QListViewItem(item);
m_temp->setText(0,fileInfo->fileName());
m_temp
->setPixmap
(0,
QPixmap("/root/qt/Tree/images/fileunchecked.png"));
}
}
}
connect ( listView ,SIGNAL(pressed(QListViewItem*)),this,SLOT(reverse_images(QListViewItem*)));
}
}
void Form1 :: reverse_images(QListViewItem* item)
{
pixmap=item->pixmap (0);
image=pixmap->convertToImage ();
QImage *image1
=new QImage("/root/qt/Tree/images/folderunchecked.png");
QImage *image2
=new QImage("/root/qt/Tree/images/folderchecked.png");
QImage *image3
=new QImage("/root/qt/Tree/images/fileunchecked.png");
QImage *image4
=new QImage("/root/qt/Tree/images/filechecked.png");
if(image1->operator==(image)==true)
{
item
->setPixmap
(0,
QPixmap("/root/qt/Tree/images/folderchecked.png"));
}
else if(image2->operator==(image)==true)
{
item
->setPixmap
(0,
QPixmap("/root/qt/Tree/images/folderunchecked.png"));
}
else if(image3->operator==(image)==true)
{
item
->setPixmap
(0,
QPixmap("/root/qt/Tree/images/filechecked.png"));
}
else if(image4->operator==(image)==true)
{
item
->setPixmap
(0,
QPixmap("/root/qt/Tree/images/fileunchecked.png"));
}
}
#include <qfiledialog.h>
#include <qlistview.h>
#include <qstring.h>
#include <qfile.h>
#include <qfileinfo.h>
#include <qstringlist.h>
#include<qmessagebox.h>
#include <qpixmap.h>
#include <qdir.h>
#include <qstringlist.h>
void Form1::init()
{
listView->setColumnWidth(1,0);
listView->header()->setResizeEnabled(false,1);
}
void Form1::fileOpen()
{
QListViewItem* root=new QListViewItem(listView);
m_source = QFileDialog::getExistingDirectory(
"/home/",
this,
"get existing directory",
"Choose a directory",
TRUE );
root->setText(0,m_source);
CreateDirTree(root,m_source);
init();
}
void Form1::CreateDirTree(QListViewItem *item,QString path)
{
QDir dir(path);
QDir dir1;
const QFileInfoList * dirs=dir.entryInfoList();
{
if(dirs)
{
QFileInfoListIterator it(*dirs);
QFileInfo * fileInfo;
while(fileInfo=it.current())
{
++it;
if(fileInfo->fileName() =="." || fileInfo->fileName() =="..")
;
else if (fileInfo->isDir())
{
QString FilePath;
FilePath =path +"/"+ fileInfo->fileName();
m_temp = new QListViewItem(item);
m_temp->setText(0,fileInfo->fileName());
m_temp->setPixmap(0,QPixmap("/root/qt/Tree/images/folderunchecked.png"));
CreateDirTree(m_temp,FilePath);
}
else
{
m_temp = new QListViewItem(item);
m_temp->setText(0,fileInfo->fileName());
m_temp->setPixmap(0,QPixmap("/root/qt/Tree/images/fileunchecked.png"));
}
}
}
connect ( listView ,SIGNAL(pressed(QListViewItem*)),this,SLOT(reverse_images(QListViewItem*)));
}
}
void Form1 :: reverse_images(QListViewItem* item)
{
const QPixmap *pixmap;
pixmap=item->pixmap (0);
QImage image;
image=pixmap->convertToImage ();
QImage *image1=new QImage("/root/qt/Tree/images/folderunchecked.png");
QImage *image2=new QImage("/root/qt/Tree/images/folderchecked.png");
QImage *image3=new QImage("/root/qt/Tree/images/fileunchecked.png");
QImage *image4=new QImage("/root/qt/Tree/images/filechecked.png");
if(image1->operator==(image)==true)
{
item->setPixmap(0,QPixmap("/root/qt/Tree/images/folderchecked.png"));
}
else if(image2->operator==(image)==true)
{
item->setPixmap(0,QPixmap("/root/qt/Tree/images/folderunchecked.png"));
}
else if(image3->operator==(image)==true)
{
item->setPixmap(0,QPixmap("/root/qt/Tree/images/filechecked.png"));
}
else if(image4->operator==(image)==true)
{
item->setPixmap(0,QPixmap("/root/qt/Tree/images/fileunchecked.png"));
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks