×
Namespaces

Variants
Actions
Revision as of 04:16, 11 October 2012 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Dynamic Widget Reflection

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Code ExampleTested with
Devices(s): Windows Xp
Compatibility
Platform(s): Windows/ Linux
Symbian
Article
Keywords: Widget
Created: somnathbanik (30 Mar 2011)
Last edited: hamishwillee (11 Oct 2012)


Contents

Description

This article has many functionality. Dynamic Widget, Widget Reflection, Video Playback are the main attraction. Along with that I have used OpenGL in this application. Below are some code sample and the complete project is wrap up into the zip file. In the GUI there is a QGraphicsView widget. I promoted it to imageViewer2d. In mainWindow.cpp you can see how it works for images and background. You can also give a try to do something when scroll right limit it reached.

Prerequisite

Take a video and image file and copy to the project folder. Set the video and image file path in the mainWindow.cpp.

shawn.pro

QT       += core gui opengl phonon
DEFINES += QT_OPENGL_SUPPORT
 
TARGET = shawn
TEMPLATE = app
 
 
SOURCES += src/main.cpp\
src/mainwindow.cpp \
src/imageviewer2d.cpp \
src/imagecontainer.cpp
 
HEADERS += src/mainwindow.h \
src/imageviewer2d.h \
src/imagecontainer.h \
src/defines.h
 
FORMS += src/mainwindow.ui \
src/video.ui


mainwindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H
 
#include <QMainWindow>
 
namespace Ui {
class MainWindow;
}
 
class MainWindow : public QMainWindow
{
Q_OBJECT
 
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
 
private slots:
void on_pushButton_clicked();
void onScrollRightLimitReached();
 
void on_pushButton_2_clicked();
 
private:
Ui::MainWindow *ui;
};
 
#endif // MAINWINDOW_H


mainwindow.cpp

#include <phonon/mediaobject.h>
#include <phonon/videowidget.h>
#include <phonon/audiooutput.h>
#include <phonon/seekslider.h>
#include <phonon/volumeslider.h>
#include <phonon/videoplayer.h>
 
#include <QImage>
#include <QDebug>
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "imageviewer2d.h"
#include "imagecontainer.h"
 
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
 
ui->viewer->setImageContainerSize(QSize(150,200),
QSize(15,15));
ui->viewer->setBackgroundGradient(QColor(0,0,200),
QColor(0,0,0),
QColor(50,0,0));
ui->viewer->set_rows(2);
imageContainer::images_color = QColor(35,70,190);
imageContainer::videos_color = QColor(127,4,6);
imageContainer::images_text_color = QColor(255,255,0);
imageContainer::videos_text_color = QColor(255,255,0);
 
connect(ui->viewer, SIGNAL(onScrollRightLimitReached()),
this, SLOT(onScrollRightLimitReached()) );
}
 
MainWindow::~MainWindow()
{
delete ui;
}
 
void MainWindow::on_pushButton_clicked()
{
QPixmap img("C:/Qt/workspace/Example/shawn/0001.jpg");
imageStruct is;
is.description_row1 = "description row 1";
is.description_row2 = "description row 2";
is.description_row3 = "description row 3";
is.ID=0;
is.image_source = "C:/Qt/workspace/Example/shawn/0001.jpg";
is.kind = CONTAINER_KIND_IMAGE;
ui->viewer->add_imageContainer(img, is);
ui->viewer->addItemList_to_scene();
}
 
void MainWindow::onScrollRightLimitReached()
{
qDebug() << "Scroll right limit reached";
ui->viewer->stopInertia();
}
 
 
#include <QFrame>
#include "ui_video.h"
void MainWindow::on_pushButton_2_clicked()
{
Ui_Form *videoForm = new Ui::Form;
videoForm->setupUi(this);
videoForm->widget->setGeometry(0,0,300,150);
 
ui->viewer->setImageContainerSize(QSize(300,150), QSize(10,10));
 
imageContainer *ic = new imageContainer(videoForm->widget);
ui->viewer->add_widget(ic);
videoForm->videoPlayer->load(QString("C:/Qt/workspace/Example/shawn/Aaj.mp4"));
videoForm->videoPlayer->play();
}

Source Code

The full source code presented in this article is available here File:DynamicWidget.zip

--somnathbanik

This page was last modified on 11 October 2012, at 04:16.
135 page views in the last 30 days.
×