Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
464 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* This work is licensed under the Creative Commons Attribution 3.0 Unported | ||
* License. To view a copy of this license, visit | ||
* http://creativecommons.org/licenses/by/3.0/ or send a letter to Creative | ||
* Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA. | ||
*/ | ||
|
||
/* StackOverflow reference: | ||
* http://stackoverflow.com/questions/12307119/qgraphicssceneitems-returns-no-items-for-a-given-rect | ||
*/ | ||
|
||
#include "MainWindow.h" | ||
#include "ui_MainWindow.h" | ||
|
||
#include <QDebug> | ||
#include <QKeyEvent> | ||
#include <QGraphicsPixmapItem> | ||
|
||
MainWindow::MainWindow(QWidget *parent) : | ||
QMainWindow(parent), | ||
ui(new Ui::MainWindow) | ||
, scene(new QGraphicsScene()) | ||
{ | ||
ui->setupUi(this); | ||
|
||
ui->graphicsView->setScene(scene); | ||
ui->graphicsView->installEventFilter(this); | ||
ui->graphicsView->show(); | ||
|
||
for (int y = 0; y < 20; ++y) { | ||
for (int x = 0; x < 20; ++x) { | ||
QPixmap pixmap("desert.png"); | ||
QGraphicsPixmapItem* newItem(scene->addPixmap(pixmap)); | ||
newItem->setPos(x * 25, y * 25); | ||
newItem->setOpacity(0.01); | ||
qDebug() << newItem << newItem->isVisible(); | ||
} | ||
} | ||
} | ||
|
||
MainWindow::~MainWindow() | ||
{ | ||
delete ui; | ||
delete scene; | ||
} | ||
|
||
bool MainWindow::eventFilter(QObject *obj, QEvent *event) | ||
{ | ||
if(event->type() == QEvent::KeyPress) { | ||
QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event); | ||
if (keyEvent->key() == Qt::Key_Space) { | ||
QRectF rect(0, 0, 25 * 3, 25 * 3); | ||
QList<QGraphicsItem*> items(scene->items(rect, Qt::ContainsItemBoundingRect, Qt::AscendingOrder)); | ||
qDebug() << items; | ||
foreach (QGraphicsItem *item, items) { | ||
item->setOpacity(1.0); | ||
} | ||
} | ||
return true; | ||
} | ||
return QObject::eventFilter(obj, event); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* This work is licensed under the Creative Commons Attribution 3.0 Unported | ||
* License. To view a copy of this license, visit | ||
* http://creativecommons.org/licenses/by/3.0/ or send a letter to Creative | ||
* Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA. | ||
*/ | ||
|
||
/* StackOverflow reference: | ||
* http://stackoverflow.com/questions/12307119/qgraphicssceneitems-returns-no-items-for-a-given-rect | ||
*/ | ||
|
||
#include <QMainWindow> | ||
#include <QWidget> | ||
#include <QEvent> | ||
#include <QGraphicsScene> | ||
#include "ui_MainWindow.h" | ||
|
||
class MainWindow : public QMainWindow { | ||
Q_OBJECT | ||
|
||
public: | ||
|
||
MainWindow(QWidget* parent); | ||
~MainWindow(); | ||
bool eventFilter(QObject *obj, QEvent *event); | ||
|
||
Ui_MainWindow* ui; | ||
QGraphicsScene* scene; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>MainWindow</class> | ||
<widget class="QMainWindow" name="MainWindow"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>800</width> | ||
<height>600</height> | ||
</rect> | ||
</property> | ||
<property name="windowTitle"> | ||
<string>MainWindow</string> | ||
</property> | ||
<widget class="QWidget" name="centralwidget"> | ||
<layout class="QVBoxLayout" name="verticalLayout"> | ||
<item> | ||
<widget class="QGraphicsView" name="graphicsView"/> | ||
</item> | ||
</layout> | ||
</widget> | ||
<widget class="QMenuBar" name="menubar"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>800</width> | ||
<height>23</height> | ||
</rect> | ||
</property> | ||
</widget> | ||
<widget class="QStatusBar" name="statusbar"/> | ||
</widget> | ||
<resources/> | ||
<connections/> | ||
</ui> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# This work is licensed under the Creative Commons Attribution 3.0 Unported | ||
# License. To view a copy of this license, visit | ||
# http://creativecommons.org/licenses/by/3.0/ or send a letter to Creative | ||
# Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA. | ||
|
||
TEMPLATE = app | ||
QT = gui core | ||
|
||
CONFIG += qt warn_on | ||
FORMS = MainWindow.ui | ||
HEADERS = MainWindow.h | ||
SOURCES = MainWindow.cpp main.cpp |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* This work is licensed under the Creative Commons Attribution 3.0 Unported | ||
* License. To view a copy of this license, visit | ||
* http://creativecommons.org/licenses/by/3.0/ or send a letter to Creative | ||
* Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA. | ||
*/ | ||
|
||
/* StackOverflow reference: | ||
* http://stackoverflow.com/questions/12307119/qgraphicssceneitems-returns-no-items-for-a-given-rect | ||
*/ | ||
|
||
#include "MainWindow.h" | ||
|
||
int main(int argc, char ** argv) { | ||
|
||
QApplication app( argc, argv ); | ||
|
||
MainWindow win(0); | ||
win.show(); | ||
app.connect( &app, SIGNAL( lastWindowClosed() ), &app, SLOT( quit() ) ); | ||
|
||
return app.exec(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# This work is licensed under the Creative Commons Attribution 3.0 Unported | ||
# License. To view a copy of this license, visit | ||
# http://creativecommons.org/licenses/by/3.0/ or send a letter to Creative | ||
# Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA. | ||
|
||
TEMPLATE = app | ||
QT = core | ||
CONFIG += console qt warn_on | ||
SOURCES = main.cpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* This work is licensed under the Creative Commons Attribution 3.0 Unported | ||
* License. To view a copy of this license, visit | ||
* http://creativecommons.org/licenses/by/3.0/ or send a letter to Creative | ||
* Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA. | ||
*/ | ||
|
||
/* StackOverflow reference: | ||
* http://stackoverflow.com/questions/12501140/qt-qstring-from-qdatastream | ||
*/ | ||
|
||
#include <QCoreApplication> | ||
#include <QDebug> | ||
#include <QDataStream> | ||
#include <QBuffer> | ||
|
||
void myFunc(QDataStream& in) | ||
{ | ||
quint8 v; | ||
in >> v; | ||
qDebug() << v; | ||
// Ok, I caught v value successfuly | ||
QString s; | ||
in >> s; | ||
qDebug() << s; | ||
// Didnt work :< | ||
} | ||
|
||
|
||
int main(int argc, char ** argv) { | ||
QCoreApplication a(argc, argv); | ||
|
||
QBuffer buffer; | ||
buffer.open(QBuffer::ReadWrite); | ||
|
||
// write test data into the biffer | ||
QDataStream out(&buffer); | ||
quint8 ival = 42; | ||
QString sval = "Qt"; | ||
out << ival; | ||
out << sval; | ||
|
||
// read back data | ||
buffer.seek(0); | ||
myFunc(out); | ||
|
||
|
||
return a.exec(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* This work is licensed under the Creative Commons Attribution 3.0 Unported | ||
* License. To view a copy of this license, visit | ||
* http://creativecommons.org/licenses/by/3.0/ or send a letter to Creative | ||
* Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA. | ||
*/ | ||
|
||
/* StackOverflow reference: | ||
* http://stackoverflow.com/questions/12606365/how-to-match-tab-length-to-a-number-of-spaces-in-qt | ||
*/ | ||
|
||
#include "MainWindow.h" | ||
#include "ui_MainWindow.h" | ||
|
||
#include <QDebug> | ||
#include <QKeyEvent> | ||
#include <QGraphicsPixmapItem> | ||
|
||
MainWindow::MainWindow(QWidget *parent) : | ||
QMainWindow(parent), | ||
ui(new Ui::MainWindow) { | ||
|
||
ui->setupUi(this); | ||
ui->textEdit->setFontFamily("Courier New"); | ||
QFontMetrics fm(ui->textEdit->currentFont()); | ||
int spaceWidth = fm.width(" "); | ||
int tabStop = spaceWidth * 4; | ||
ui->textEdit->setTabStopWidth(tabStop + 1); | ||
ui->textEdit->setText("\tAfter one tab\n" | ||
" After 4 spaces\n" | ||
"\t\tAfter two tabs\n" | ||
" After 8 spaces\n" | ||
"\t\t\t\t\t\tAfter six tabs\n" | ||
" After 24 spaces\n" | ||
"\t\t\t\t\t\t\t\t\t\t\t\tAfter 12 tabs\n" | ||
" After 48 spaces\n"); | ||
} | ||
|
||
MainWindow::~MainWindow() | ||
{ | ||
delete ui; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* This work is licensed under the Creative Commons Attribution 3.0 Unported | ||
* License. To view a copy of this license, visit | ||
* http://creativecommons.org/licenses/by/3.0/ or send a letter to Creative | ||
* Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA. | ||
*/ | ||
|
||
/* StackOverflow reference: | ||
* http://stackoverflow.com/questions/12606365/how-to-match-tab-length-to-a-number-of-spaces-in-qt | ||
*/ | ||
|
||
#include <QMainWindow> | ||
#include <QWidget> | ||
#include "ui_MainWindow.h" | ||
|
||
class MainWindow : public QMainWindow { | ||
Q_OBJECT | ||
|
||
public: | ||
|
||
MainWindow(QWidget* parent); | ||
~MainWindow(); | ||
|
||
Ui_MainWindow* ui; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>MainWindow</class> | ||
<widget class="QMainWindow" name="MainWindow"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>800</width> | ||
<height>600</height> | ||
</rect> | ||
</property> | ||
<property name="windowTitle"> | ||
<string>MainWindow</string> | ||
</property> | ||
<widget class="QWidget" name="centralwidget"> | ||
<layout class="QVBoxLayout" name="verticalLayout"> | ||
<item> | ||
<widget class="QTextEdit" name="textEdit"/> | ||
</item> | ||
</layout> | ||
</widget> | ||
<widget class="QMenuBar" name="menubar"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>800</width> | ||
<height>23</height> | ||
</rect> | ||
</property> | ||
</widget> | ||
<widget class="QStatusBar" name="statusbar"/> | ||
</widget> | ||
<resources/> | ||
<connections/> | ||
</ui> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# This work is licensed under the Creative Commons Attribution 3.0 Unported | ||
# License. To view a copy of this license, visit | ||
# http://creativecommons.org/licenses/by/3.0/ or send a letter to Creative | ||
# Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA. | ||
|
||
TEMPLATE = app | ||
QT = gui core | ||
CONFIG += qt warn_on | ||
FORMS = MainWindow.ui | ||
HEADERS = MainWindow.h | ||
SOURCES = MainWindow.cpp main.cpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* This work is licensed under the Creative Commons Attribution 3.0 Unported | ||
* License. To view a copy of this license, visit | ||
* http://creativecommons.org/licenses/by/3.0/ or send a letter to Creative | ||
* Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA. | ||
*/ | ||
|
||
/* StackOverflow reference: | ||
* http://stackoverflow.com/questions/12606365/how-to-match-tab-length-to-a-number-of-spaces-in-qt | ||
*/ | ||
|
||
#include "MainWindow.h" | ||
|
||
int main(int argc, char ** argv) { | ||
|
||
QApplication app( argc, argv ); | ||
|
||
MainWindow win(0); | ||
win.show(); | ||
app.connect( &app, SIGNAL( lastWindowClosed() ), &app, SLOT( quit() ) ); | ||
|
||
return app.exec(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
cmake_minimum_required (VERSION 2.6) | ||
project (conflict) | ||
add_executable(conflict foo/conflict.cpp bar/conflict.cpp main.cpp) | ||
include_directories("/usr/include/qt4/QtGui" "/usr/include/qt4") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# This work is licensed under the Creative Commons Attribution 3.0 Unported | ||
# License. To view a copy of this license, visit | ||
# http://creativecommons.org/licenses/by/3.0/ or send a letter to Creative | ||
# Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA. | ||
|
||
TEMPLATE = app | ||
QT = gui core | ||
CONFIG += qt warn_on | ||
|
||
HEADERS = foo/conflict.h bar/conflict.h | ||
SOURCES = foo/conflict.cpp bar/conflict.cpp |
Oops, something went wrong.