WallpaperChooser::WallpaperChooser(QWidget *parent) : QWidget(parent) // This widget is shown on the bottom of the screen,
                                                                      // it allows to select a wallpaper and some other parameters
{
    mainColor = QColor(Qt::white); // Used to build the gradient with a cool color, TODO: make it changeable
    m_settings = new QSettings("Desktop", "Desktop");
    m_URLList = m_settings->value("WallpaperList").toStringList();
    m_settings->value("BackgroundColor", Qt::black).value<QColor>();

    layout = new QGridLayout(this);

    wallpaperList = new QListWidget();
    wallpaperList->setStyleSheet("QListWidget{background-color: transparent; border: none;}");
    wallpaperList->setViewMode(QListView::IconMode);
    wallpaperList->setIconSize(QSize(100, 100));
    wallpaperList->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
    wallpaperList->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    wallpaperList->setFlow(QListWidget::TopToBottom);
    wallpaperList->setMovement(QListWidget::Static);
    wallpaperList->setResizeMode(QListWidget::Adjust);
    connect(wallpaperList, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(wallSelected(QListWidgetItem*)));
    layout->addWidget(wallpaperList, 0, 0, 2, 4);
    WallsThread *thread = new WallsThread();
    thread->run(wallpaperList, m_URLList);

    addb = new QPushButton(QIcon::fromTheme("add"), tr("Add"));
    connect(addb, SIGNAL(clicked()), SLOT(addWall()));
    layout->addWidget(addb, 0, 4);
    removeb = new QPushButton(QIcon::fromTheme("remove"), tr("Remove"));
    connect(removeb, SIGNAL(clicked()), SLOT(removeWall()));
    layout->addWidget(removeb, 1, 4);

    colorb = new QPushButton(tr("Background color"));
    connect(colorb, SIGNAL(clicked()), SLOT(colorSelected()));
    layout->addWidget(colorb, 2, 0);

    stylecb = new QComboBox();
    stylecb->insertItems(0, QStringList() << tr("Zoomed") << tr("Centered") << tr("Resized") << tr("Enlarged"));
    stylecb->setCurrentIndex(m_settings->value("Style", Zoomed).toInt());
    connect(stylecb, SIGNAL(currentIndexChanged(int)), this, SLOT(styleSelected(int)));
    layout->addWidget(stylecb, 2, 1);

    layout->addItem(new QSpacerItem(1, 1, QSizePolicy::Expanding), 2, 2);
    okb = new QPushButton(QIcon::fromTheme("dialog-apply"), tr("Apply"));
    connect(okb, SIGNAL(clicked()), this, SLOT(emitHide()));
    layout->addWidget(okb, 2, 4);
}
Exemple #2
0
void Walls::addWall(const Edge &e, TileMap &tilemap, TileMapEntry &tme)
{
	/* this is a pretty serious function...*/
	/* basic idea:
		* The Wall constructor adds tile sized edges from class Tiles to the 
			right place
		* addWall checks this edge against it's neighbors to determine if it
			can be combined or removed
			* two collinear adjacent (connected by a point) segments, with 
				the same normal, and of the same type can be combined
			* two collinear segments that intersect such that one segment
				contains the other, with opposite normals of the same type
				(or of certain other types, see below) can be removed
		* otherwise, add it to the list
	*/

	const Segment &s = e.segment + tme.getULCorner();
	Segment *add = NULL;
	const Wall *remove = NULL;

	int tileI = tme.getI(), tileJ = tme.getJ();
	WallSet set;

	/* add walls to set from <i-1,j-1>,<i,j-1>,<i+1,j-1>,<i-1,j> */
	set.addFromTile( tilemap.index(tileI-1, tileJ-1) );
	set.addFromTile( tilemap.index(tileI+0, tileJ-1) );
	set.addFromTile( tilemap.index(tileI+1, tileJ-1) );
	set.addFromTile( tilemap.index(tileI-1, tileJ+0) );

	WallSet::Iterator i;

	for (i = set.begin(); i != set.end(); ++i)
	{
		const Edge &e2 = (*i)->wall;
		const Segment &t = e2.segment;

		/* p0 and p1 are return values */
		Point p0, p1;
		Segment::IntersectType it = s.intersect(t,p0,p1);
		switch (it)
		{
		case Segment::DISJOINT:
		case Segment::POINT:
			continue;
		case Segment::COLLINEAR_POINT:
			/* normals must be the same to combine */
			if (s.normal != t.normal)
				break;

			/* can only combine like types */
			if (e.type != e2.type)
				break;

			if (p0 == t.p0)
			{
				/* segment goes s -> t
				 extend t back to s
				*/

				add = new Segment(s.p0, t.p1);
			}
			else
			{
				/* segment goes t -> s
				extend t to s
				*/

				add = new Segment(t.p0, s.p1);
			}

			remove = *i;
			break;
		case Segment::SEGMENT:
			/* normals must be opposite to cancel out */
			/* (shouldn't be otherwise, anyway -- it would imply that two 
				tiles were added to the same place) */
			assert(s.normal == -t.normal);

			/* can only cancel like types, or a one way with a weak, or a ladder top with a ladder */
			if (e.type != e2.type && 
				!( (e.type == Edge::ONE_WAY && e2.type == Edge::WEAK) ||
					(e.type == Edge::WEAK && e2.type == Edge::ONE_WAY) ||
					(e.type == Edge::LADDER_TOP && e2.type == Edge::LADDER) ||
					(e.type == Edge::LADDER && e2.type == Edge::LADDER_TOP) )
				)
				break;

			/* delete add if it has been created */
			if (add)
				delete add;

			Wall *new1 = NULL, *new2 = NULL;
			Segment *s1 = NULL, *s2 = NULL;

			/* here we make some assumptions about the way edges are defined in
				Tile::makeTiles and how Segment::intersect returns p0 and p1:
				* edges are defined in clockwise order
				* p0 and p1 are returned as distances along t (the second segment),
					where p0 is closest to t.p0 and p1 is closest to t.p1
			*/

			/* we know that if s and t intersect that either
				* s contains t
				* t contains s
				* neither of above
					but this can't happen because but s must always be at 
					least as small as t (because t could have been combined).

				* if s and t are the same size, p0 = t.p0 and p1 = t.p1
				* if s is smaller than t, p0 will be the point closest to
					t.p0 (which is s.p1, because s and t's points are declared
					in opposite directions, because they're normals are opposite)
					and p1 will be the point closest to t.p1 (s.p0 for the same
					reason).
			*/

			if ( p0 == t.p0 && p1 == t.p1 )
			{
				/* t is the short segment,
				   remove t portion of s, keep ends (if any) */

				if (s.p0 != p1) s1 = new Segment(s.p0, p1);
				if (p0 != s.p1) s2 = new Segment(p0, s.p1);
			}
			else if ( p0 == s.p1 && p1 == s.p0 )
			{
				/* s is the short segment,
					remove s portion of t, keep ends (if any) */

				if (t.p0 != p0) s1 = new Segment(t.p0, p0);
				if (p1 != t.p1) s2 = new Segment(p1, t.p1);
			}
			else
			{
				/* shouldn't happen */
				assert(0);
			}

			/* add the new walls */
			if (s1)
			{
				walls.push_back(Edge(*s1, e2.type));
				new1 = &walls.back();
				delete s1;
			}

			if (s2)
			{
				walls.push_back(Edge(*s2, e2.type));
				new2 = &walls.back();
				delete s2;
			}

			/* remap the old wall */
			remapWall( **i, new1, new2 );
			/* remove the old wall */
			removeWall(*i);
			return;
			break;
		}
	}

	if (add != NULL)
	{
		/* combine */
		walls.push_back( Wall(Edge(*add, e.type)) );
		delete(add);

		Wall *new1 = &walls.back();

		tme.addWall( new1 );
		new1->addTile(&tme);

		remapWall(*remove, new1, NULL);
		removeWall(remove);
	}
	else
	{
		Wall w( Edge(s,e.type) );

		/* add the TileMapEntry to the wall */
		w.addTile(&tme);
		/* add the Wall to the main list */
		walls.push_back( w );
		/* add the Wall to the TileMapEntry list */
		tme.addWall( &walls.back() );
	}
}