example/DemoGUI/GridView.cpp
author cgandhi
Thu, 05 Aug 2010 16:35:33 +0530
changeset 16 b78fa4cdbf2b
permissions -rw-r--r--
pushing the demo application
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
     1
#include "GridView.h"
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
     2
#include "ScreenSize.h"
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
     3
#include <qgridlayout.h>
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
     4
#include <qpushbutton.h>
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
     5
#include <qdebug.h>
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
     6
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
     7
GridView::GridView()
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
     8
{
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
     9
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    10
}
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    11
GridView::~GridView()
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    12
{
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    13
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    14
}
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    15
void GridView::CreateGridView(QStringList aIconPath, QStringList names)
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    16
{
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    17
	qDebug()<<"Inside GridView::CreateGridView()";
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    18
	qDebug()<<"aIconPath count = "<<aIconPath.count();
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    19
	qDebug()<<"names count = "<<names.count();
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    20
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    21
    int row;
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    22
    int col;
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    23
    QWidget* widget = new QWidget();
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    24
    QGridLayout* GridLayout = new QGridLayout(widget);
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    25
    if((6 == aIconPath.count()) || (5 == aIconPath.count()))
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    26
    {
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    27
        row = 3;
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    28
        col = 2;
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    29
    }
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    30
    else if((4 == aIconPath.count()) || (3 == aIconPath.count()))
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    31
    {
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    32
        row = col = 2;
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    33
    }
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    34
    else if((2 == aIconPath.count()) || (1 == aIconPath.count()))
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    35
    {
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    36
        row = 1;
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    37
        col = 2;
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    38
    }
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    39
    else if(0 == aIconPath.count())
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    40
    {
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    41
        row = col = 0;
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    42
    }
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    43
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    44
    int rowSpace = (ScreenSize::GetScreenRect().height() - (KHeadNameHeight+ToolbarIconHeight+2*KWidgetGapFactor))/row;
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    45
    int colSpace = (ScreenSize::GetScreenRect().width() - 2*KWidgetGapFactor )/col;
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    46
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    47
    int index = 0;
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    48
    for(int i=0;i<row;i++)
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    49
    {
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    50
        for(int j=0;j<col;j++)
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    51
        {
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    52
        QPushButton *pushBtn = new QPushButton();
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    53
        qDebug()<<"name = "<<names[index];
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    54
        //pushBtn->
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    55
        pushBtn->setGeometry(i*colSpace,(j*rowSpace + KWidgetGapFactor),colSpace,rowSpace);
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    56
        pushBtn->setIconSize(QSize(colSpace,colSpace));
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    57
        qDebug()<<"icon = "<<aIconPath[index];
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    58
        pushBtn->setIcon(QIcon(aIconPath[index]));
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    59
        GridLayout->addWidget(pushBtn,i,j);
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    60
        pushBtn->show();
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    61
        
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    62
        index++;
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    63
        if(index == names.count())
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    64
        	{
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    65
        	qDebug()<<"Count became same so exiting";
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    66
			break;
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    67
        	}
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    68
        }
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    69
	if(index == names.count())
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    70
		{
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    71
		qDebug()<<"Count became same so exiting";
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    72
		break;
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    73
		}
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    74
    }
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    75
	//return widget;
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    76
b78fa4cdbf2b pushing the demo application
cgandhi
parents:
diff changeset
    77
}