Qt image browser (2)

Source: Internet
Author: User
Tags image flip

The QT image browser program written in the front is written in the QT creator environment under the window, and the running effect on the window is correct, but it needs to be compiled in the QT environment under Linux, therefore, it is not ideal to run the program after compiling in Linux. The phenomenon is that after opening the image below Linux, The up/down flip is not displayed in the order that has been arranged in the folder, it is a fixed order, which leads to the deletion failure. Finally, it changes the code of the function to traverse all images in the folder where the image is located. In this way, the Traversal method is changed, finally, the ideal results were obtained. The Code is as follows:

Csimagescan. cpp:

# Include "csimagescan. H"
# Include "ui_csimagescan.h"

Csimagescan: csimagescan (qwidget * parent ):
Qdialog (parent ),
UI (new UI: csimagescan)
{
UI-> setupui (this );
Position = 0;
Left = 0;
Right = 0;
Num_roll = 0;

Setwindowflags (QT: framelesswindowhint); // remove the title bar.
Int screen_w = qapplication: desktop ()-> width ();
Int screen_h = qapplication: desktop ()-> height ();

Resize (screen_w, screen_h );
// Int win_w = width ();
// Int win_h = height ();
//
Printf ("abcdefghigk =====% D, ------ 12345678910 =========% D ----------- \ n", screen_w, screen_h );
/*
Qpushbutton pbexit = new qpushbutton (this );
Pbexit-> setobjectname (qstring: fromutf8 ("pbexit "));
Pbexit-> setgeometry (qrect (803,728 ));
Pbexit-> setfocuspolicy (QT: nofocus );
Pbexit-> setflat (true );
*/
UI-> pre-> setgeometry (523,728 );
UI-> next-> setgeometry (603,728 );
// UI-> rotuteleft-> setgeometry (203,728 );
// UI-> rotuteright-> setgeometry (283,728 );
UI-> pbdelete-> setgeometry (723,728 );
UI-> pbexit-> setgeometry (qrect (803,728 ));
UI-> rotuteleft-> setenabled (false );
UI-> rotuteright-> setenabled (false );

Qpixmap m_pixmap ("Res/pre.png ");
Qicon m_icon;
M_icon.addpixmap (m_pixmap );
UI-> pre-> seticon (m_icon );
UI-> pre-> seticonsize (qsize (40, 40 ));

M_pixmap.load ("Res/next.png ");
M_icon.addpixmap (m_pixmap );
UI-> next-> seticon (m_icon );
UI-> next-> seticonsize (qsize (40, 40 ));
/*
M_pixmap.load ("Res/left.png ");
M_icon.addpixmap (m_pixmap );
UI-> rotuteleft-> seticon (m_icon );
UI-> rotuteleft-> seticonsize (qsize (60, 60 ));

M_pixmap.load ("Res/right.png ");
M_icon.addpixmap (m_pixmap );
UI-> rotuteright-> seticon (m_icon );
UI-> rotuteright-> seticonsize (qsize (60, 60 ));
*/
M_pixmap.load ("Res/imgdelete.png ");
M_icon.addpixmap (m_pixmap );
UI-> pbdelete-> seticon (m_icon );
UI-> pbdelete-> seticonsize (qsize (40, 40 ));

M_pixmap.load ("Res/exit.png ");
M_icon.addpixmap (m_pixmap );
UI-> pbexit-> seticon (m_icon );
UI-> pbexit-> seticonsize (qsize (40, 40 ));
}

Csimagescan ::~ Csimagescan ()
{
Delete UI;
}

/*
Void csimagescan: drawimageonsrc (qstring & Str)
{
//
UI-> label-> setpixmap (qpixmap (STR ));
//
}
*/

// Close the button slot in the Image Browsing dialog box
Void csimagescan: on_pbexit_clicked ()
{
This-> close ();
}
// Enable the Image Browsing Function
Void csimagescan: on_open_clicked ()
{
Position = 0;
Stringlist. Clear ();
// Printf ("% s \ n", filepath. toascii (). constdata ());
Filepath = qfiledialog: getopenfilename (null, qobject: TR ("open image "),".",
Qobject: TR ("image files (*. jpg *. PNG *. BMP )"));

Filelist = filepath. Split ("/");
Filelist. removelast ();
Folderpath = filelist. Join ("/");
Setpixmap (filepath );
Printf ("----- % d ------ \ n", position );
}

// Traverse all the images in the folder where the image is located
Void csimagescan: open_file ()
{
Qdir Dir (folderpath );
Qfileinfolist filelist;
Qfileinfo curfile;
Qstringlist filters;
// Filters <"*. jpg" <"*. PNG ";
Filters <"*. jpg" <"*. PNG" <"*. BMP ";
Filelist = dir. entryinfolist (filters, qdir: dirs | qdir: Files
| Qdir: readable | qdir: writable
| Qdir: hidden | qdir: nodotanddotdot
, Qdir: Name );
Int I = 0;
If (filelist. Size ()> 0)
{
// Curfile = filelist [position];
While (I <filelist. Size ())
{
Curfile = filelist [I];
If (filepath = curfile. filepath ())
Position = I;
Stringlist <curfile. filepath ();
Printf ("---- Delete ---- % d ---------- \ n", I );
Printf ("% s ---- \ n", curfile. filepath (). toascii (). constdata ());
// Printf ("% s ---- \ n", filepath. toascii (). constdata ());
I ++;
}

}
}

// Forward the image
Void csimagescan: on_pre_clicked ()
{
Left = 0;
Right = 0;
Num_roll = 0;
If (0 = stringlist. Size ())
{
Printf ("Get pre image erron \ n ");
Return;
}
Position --;
If (position <0)
{
Position = stringlist. Size ()-1;
}

Filepath = stringlist. At (position );
Setpixmap (filepath );
Printf ("--- pre ---- % d ------------------- \ n", position );
Printf ("% s ---- \ n", filepath. toascii (). constdata ());
}

// Image flip
Void csimagescan: on_next_clicked ()
{
Left = 0;
Right = 0;
Num_roll = 0;
If (0 = stringlist. Size ())
{
Printf ("Get Next image erron \ n ");
Return;
}
Position ++;
If (position> stringlist. Size ()-1)
{
Position = 0;
}
Filepath = stringlist. At (position );
Setpixmap (filepath );
Printf ("--- next ---- % d ------------------- \ n", position );
Printf ("% s ---- \ n", filepath. toascii (). constdata ());
}
// Rotate the image counterclockwise
Void csimagescan: on_rotuteleft_clicked ()
{
If (0 = stringlist. Size ())
{
Printf ("Get Next image erron \ n ");
Return;
}
Left = 1;
If (Left = 1 & Right = 1)
{
Num_roll --;
// Qimage image (stringlist. At (position ));
Qmatrix matrix;
// Matrix. Rotate (-90.0 * num_roll );
Matrix. Rotate (-90.0 );
Image = image. Transformed (matrix, QT: fasttransformation );
PIX = pix. fromimage (image );
Update ();
}
Else
{
Num_roll ++;
// Qimage image (stringlist. At (position ));
Image. Load (stringlist. At (position ));
Qmatrix matrix;
Matrix. Rotate (-90.0 * num_roll );
Image = image. Transformed (matrix, QT: fasttransformation );
PIX = pix. fromimage (image );
Update ();
}

}
// Rotate the image clockwise
Void csimagescan: on_rotuteright_clicked ()
{
If (0 = stringlist. Size ())
{
Printf ("Get Next image erron \ n ");
Return;
}
Right = 1;
If (Left = 1 & Right = 1)
{
// Num_roll --;
// Qimage image (stringlist. At (position ));
Qmatrix matrix;
// Matrix. Rotate (90.0 * num_roll );
Matrix. Rotate (90.0 );
Image = image. Transformed (matrix, QT: fasttransformation );
PIX = pix. fromimage (image );
Update ();
}
Else
{
Num_roll ++;
// Qimage image (stringlist. At (position ));
Image. Load (stringlist. At (position ));
Qmatrix matrix;
Matrix. Rotate (90.0 * num_roll );
Image = image. Transformed (matrix, QT: fasttransformation );
PIX = pix. fromimage (image );
Update ();
}
}
// Delete an image
Void csimagescan: on_pbdelete_clicked ()
{
If (stringlist. Size () = 0)
Return;
Qmessagebox: standardbutton RB = qmessagebox: Question (null, "warning ",
"Do you want to delete the picture? ", Qmessagebox: Yes | qmessagebox: No, qmessagebox: Yes );
If (rb = qmessagebox: Yes)
{

Stringlist. takeat (position );
Qdir Dir (folderpath );
Qfileinfolist filelist;
Qfileinfo curfile;
Qstringlist filters;
Filters <"*. jpg" <"*. PNG" <"*. BMP ";
Filelist = dir. entryinfolist (filters, qdir: dirs | qdir: Files
| Qdir: readable | qdir: writable
| Qdir: hidden | qdir: nodotanddotdot
, Qdir: Name );
If (filelist. Size ()> 0)
{
Curfile = filelist [position];
Qfile filetemp (curfile. filepath ());
Filetemp. Remove ();
Filelist. removeat (position );
// Qfile filetemp (curfile. filepath (). Remove (qstring ("_ screen"), QT: casesensitive ));
// Filetemp. Remove ();
Printf ("---- Delete ---- % d ---------- \ n", position );
Printf ("% s ---- \ n", curfile. filepath (). toascii (). constdata ());
}
If (0 = stringlist. Size ())
{
Printf ("Get Next image erron \ n ");
Return;
}
Else
{
Filepath = stringlist. At (position );
Setpixmap (filepath );
}
}
}
// Redraw the event
Void csimagescan: paintevent (qpaintevent *)
{
Qpainter painter (this );
Painter. drawpixmap (43, 0, pix );
}

Void csimagescan: setpixmap (qstring imagename)
{
PIX. Load (imagename );
Update ();
}

The code is identical elsewhere.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.