cardboard.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #ifndef CARDBOARD_H
  2. #define CARDBOARD_H
  3. #include <QDeclarativeItem>
  4. #include <QGraphicsScene>
  5. #include <QEvent>
  6. #include <QMessageService>
  7. #include <QMessage>
  8. #include <QDeclarativeView>
  9. #include <QFile>
  10. QTM_USE_NAMESPACE
  11. class CardBoard : public QDeclarativeItem {
  12. Q_OBJECT
  13. QDeclarativeView *view;
  14. public:
  15. CardBoard(QDeclarativeView *view) : QDeclarativeItem() {
  16. this->view = view;
  17. }
  18. CardBoard() : QDeclarativeItem() {
  19. this->view = view;
  20. }
  21. Q_INVOKABLE void sendMms() {
  22. QMessageService *pMessageManager = new QMessageService(this);
  23. QMessage message;
  24. message.setType(QMessage::Mms);
  25. message.setBody("Foo");
  26. QStringList images;
  27. images << "qrc:/images/1245944_74222603_854.jpg";
  28. message.appendAttachments(images);
  29. pMessageManager->compose(message);
  30. }
  31. Q_INVOKABLE void sendEmail() {
  32. QMessageService *pMessageManager = new QMessageService(this);
  33. QMessage message;
  34. message.setType(QMessage::Email);
  35. //message.setSubject("auto test");
  36. //message.setTo(QMessageAddress(QMessageAddress::Email, "swinkels@o2.pl"));
  37. QStringList *images = new QStringList();
  38. images->append("/home/user/MyDocs/Pictures/eCard_email.jpg");
  39. message.appendAttachments(*images);
  40. pMessageManager->compose(message);
  41. //pMessageManager->send(message);
  42. }
  43. Q_INVOKABLE bool fileExists(QString fileName) {
  44. QString fullName = "/home/user/MyDocs/Pictures/" + fileName;
  45. return QFile::exists(fullName);
  46. }
  47. Q_INVOKABLE bool saveJPG(QString fileName) {
  48. QPixmap pixmap = QPixmap::grabWidget(view);
  49. if (pixmap.isNull())
  50. qDebug() << "save pixmap is null";
  51. else
  52. qDebug() << "pixmap size:" << pixmap.width() << " x " << pixmap.height();
  53. QImage image = pixmap.toImage();
  54. QImage image32 = image.convertToFormat(QImage::Format_RGB32);
  55. QString fullName = "/home/user/MyDocs/Pictures/" + fileName;
  56. bool val = image32.save(fullName, "JPG", 80);
  57. if (val == false)
  58. qDebug() << "saving failed: " << fullName;
  59. else
  60. qDebug() << "saving OK: " << fullName;
  61. return val;
  62. }
  63. };
  64. #endif // CARDBOARD_H