Example of using with-grid-settings with breakpoints - susy-compass

I'm trying to figure out how to use a different grid setting based on a breakpoint but can't get it to work. Here's my code. I'm using the respond-to mixin for media queries.
$breakpoints: 'screenSmall' 480px 768px,
'screenMedium' 768px 1279px,
'screenXlarge' 1441px;
$total-columns: 4;
$column-width: 5em;
$gutter-width: 1em;
$grid-padding: $gutter-width;
[role="main"] {
#include container($total-columns);
background: #aaa;
#include susy-grid-background;
}
#include respond-to('screenSmall')
#include with-grid-settings(8,4em,1.5em,1em) {
[role="main"] { #include container; }
};
}
#include respond-to('screenMedium')
#include with-grid-settings(12,4em,1.5em,1em) {
[role="main"] { #include container; }
};
}

What exactly isn't working about it? Is there no change at all for the different breakpoints, or simply no change to the background grid image? I'm guessing the latter. If you want the background to respond to new settings, you will need to re-declare the background with those settings:
#include respond-to('screenSmall')
#include with-grid-settings(8,4em,1.5em,1em) {
[role="main"] {
#include container;
#include susy-grid-background;
}
};
}
#include respond-to('screenMedium')
#include with-grid-settings(12,4em,1.5em,1em) {
[role="main"] {
#include container;
#include susy-grid-background;
}
};
}
Of course, I think you could do it more easily with at-breakpoint rather than respond-to. But that's a different question. :)

Related

How to fix QDialog transparent background afterimage issue in qt embedded (QT4.7.3)?

I am using embedded system and I'm testing transparent QWS server where is my Qt4.7.3.
I faced the afterimage in the QDialog when moving cursor in test program which as the QWS client, but it didn't happen in the QMainWindow which in QWS server program.
Can anyone help me to fix the issue?
There is the issue
Here is test program source code.
#include "mainwindow.h"
#include <QApplication>
#include<QWSServer>
#include <QDialog>
#include <fcntl.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <linux/fb.h>
#include "qscreenlinuxfb_qws.h"
#include "qscreendriverfactory_qws.h"
#include <errno.h>
extern "C" {
extern int Test();
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QDialog w;
QWSServer::setBackground(QColor(0,0,0,0));
QWSServer::setCursorVisible(false);
w.setStyleSheet("background-color:transparent;");
w.show();
return a.exec();
}
OK I found the issue. In QT source code.
src\gui\embedded\qscreen_qws.cpp
if (!blendSize.isNull()) {
*blendbuffer = new QImage(blendSize, d_ptr->preferredImageFormat());
}
to
if (!blendSize.isNull()) {
*blendbuffer = new QImage(blendSize, d_ptr->preferredImageFormat());
QPixmap temp = QPixmap(blendSize);
temp.fill(Qt::transparent);
**blendbuffer = temp.toImage();
}

Qt serial communication using UART RS232C

I want to connect qt and a device using UART cable (RS232C) in linux.
I´m writing code, making ui and operating, but it does not work.
I want to connect when i click some button(ui) device turn on and connect.
Also i want to make a function that if i enter some command device will recognize and execute.
Below is my code , someone help me please.
<mainwindow.cpp>
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtSerialPort/QSerialPort>
#include <QMessageBox>
#include <QObject>
#include <QIODevice>
#include <QDebug>
QSerialPort serial;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
QSerialPort*port=new QSerialPort();
port->setPortName("/dev/ttyUSB0");
port->setBaudRate(QSerialPort::Baud19200);
port->setDataBits(QSerialPort::Data8);
port->setParity(QSerialPort::NoParity);
port->setStopBits(QSerialPort::OneStop);
port->setFlowControl(QSerialPort::NoFlowControl);
port->open(QIODevice::ReadWrite);
ui->setupUi(this);
serial = new QSerialPort(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_connect_clicked()
{
port=new QSerialPort();
QObject::connect(port,SIGNAL(readyRead()),this,
SLOT(on_pushButton_connect_clicked()));
if(!port->open(QIODevice::ReadWrite)){
QMessageBox::information(this, tr("connect"),
"serialcommunication start");
}
else
{
QMessageBox::critical(this, tr("fail"), serial-
>errorString());
}
}
void MainWindow::on_pushButton_disconnect_clicked()
{
port->close();
QMessageBox::information(this, tr("disconnect"), "serial
communication end");
}
<mainwindow.h>
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QtSerialPort/QSerialPort>
#include <QMessageBox>
#include <QIODevice>
#include <QDebug>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
QSerialPort*serial; //plus
QSerialPort*port;
QWidget*main_widget;
void readData();
~MainWindow();
private slots:
void on_pushButton_connect_clicked();
void on_pushButton_disconnect_clicked();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
<main.cpp>
#include "mainwindow.h"
#include <QApplication>
#include <QSerialPort>
#include <QSerialPortInfo>
#include <QDebug>
#include <QMessageBox>
#include <QIODevice>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
foreach(const QSerialPortInfo
&info,QSerialPortInfo::availablePorts()){
QSerialPort serial;
serial.setPort(info);
if (serial.open(QIODevice::ReadWrite))
serial.close();
}
MainWindow w;
w.show();
return a.exec();
}
First of all it is not guaranteed that your device will be always connected to /dev/ttyUSB0 so you'l better search for your device by QSerialPortInfo with parameter
QString manufacturer() const or quint16 productIdentifier() const or QString serialNumber() const.
Also you are creating too many QSerialPort and don't handle it. Create just one.
Here is sample code:
main.cpp
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
class QSerialPort;
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
//! Receives all the data from serial port
void readSerialData();
void on_pushButton_connect_clicked();
void on_pushButton_disconnect_clicked();
private:
Ui::MainWindow *ui;
QSerialPort *mSerialPort;
};
#endif // MAINWINDOW_H
Next check your Your product manufacturer or serial number and set here.
Also you need separate handler for received data like I created readSerialData
mainwindows.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QSerialPort>
#include <QSerialPortInfo>
#include <QMessageBox>
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
mSerialPort{new QSerialPort}
{
ui->setupUi(this);
mSerialPort->setBaudRate(QSerialPort::Baud19200);
mSerialPort->setDataBits(QSerialPort::Data8);
mSerialPort->setParity(QSerialPort::NoParity);
mSerialPort->setStopBits(QSerialPort::OneStop);
mSerialPort->setFlowControl(QSerialPort::NoFlowControl);
connect(mSerialPort, SIGNAL(readyRead()), this, SLOT(readSerialData()));
}
MainWindow::~MainWindow()
{
delete mSerialPort;
delete ui;
}
void MainWindow::readSerialData()
{
QByteArray lTmpBA;
lTmpBA = mSerialPort->readAll();
qDebug() << "Received data: " << lTmpBA;
}
void MainWindow::on_pushButton_connect_clicked()
{
foreach(QSerialPortInfo item, QSerialPortInfo::availablePorts()) {
if (item.manufacturer() == "Your product") { //past your manufacturer here
mSerialPort->setPort(item);
if(!mSerialPort->open(QIODevice::ReadWrite)){
QMessageBox::information(this, tr("connect"),
"serialcommunication start");
} else {
QMessageBox::critical(this, tr("fail"), mSerialPort->errorString());
}
} else {
qDebug() << "No connected device found";
}
}
}
void MainWindow::on_pushButton_disconnect_clicked()
{
mSerialPort->close();
}
latter if you want to send some data to your UART device just implemente slot and call method:
mSerialPort->write("Some command");

Error: Struct already definded in *.Obj

Help, I'm using VC++ and I always get the LNK2005 and LNK1169 Error when running my script, can you guys please tell me why it's happening and how to fix it, Thank you!
Code:
In the Main.cpp
#include "stdafx.h
#include <Windows.h>
#include <stdio.h>
#include <stdlib.h>
#include "Modifier.h"
using namespace std;
HWND myconsole = GetConsoleWindow();
HDC mydc = GetDC(myconsole);
int main()
{
if (Input.beg("Hello"))
{
cout << "World";
}
cin.ignore();
}
In "Modifier.cpp"
#include "stdafx.h"
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
struct {
bool beg(string a)
{
string b;
getline(cin, b);
if (b == a)
{
return true;
}
else
{
}
}
} Input;
In "Modifier.h"
#include "Modifier.cpp"
You must change your header declaration: you're inadvertently declaring a different, global "Input" variable in every .cpp that includes "Modifier.h".
SUGGESTION:
// Modifier.h
#ifndef MODIFER_H
#define MODIFIER_H
struct Input {
bool beg(string a)
{
string b;
getline(cin, b);
if (b == a)
{
return true;
}
else
{
}
}
};
#endif
Then, in Modifier.cpp:
#include "Modifier.h"
struct Input globalInput;
You should not include a .cpp in a .h. You should include headers in source files, not vice versa.
And you should definitely consider using a "class" instead of a "struct". Because, frankly, that's what your "Input" is: just a method, no state/no data.

Susy, magic grid and columns

I'm starting using Susy and there's something I'd like to accomplish but I don't know how, although I'm reading Susy's documentation and online tutorials.
I have this html:
<div class="page">
<nav>nav</nav>
<div class="main">
<div class="summary">
summary
</div>
<div class="content">
content
</div>
</div>
<footer>footer</footer>
</div>
and these Susy settings:
$total-columns: 12;
$column-width: 4em;
$gutter-width: 1em;
$grid-padding: $gutter-width;
$show-grid-backgrounds: true;
#include border-box-sizing;
// breakpoint variables
$M: 30em;
$L: 50em;
and this scss:
.page {
#include container;
#include susy-grid-background;
nav {
#include at-breakpoint($M) {
#include span-columns(2,12);
}
}
.main {
#include at-breakpoint($M) {
#include span-columns(10 omega,12);
}
.summary {
#include at-breakpoint($L) {
#include span-columns(2 omega,10);
}
}
.content {
#include at-breakpoint($L) {
#include span-columns(8,10);
}
}
}
footer {clear: both;}
That works as expected, the content is totally fluid with a max-width. However, I would like the same behaviour but starting with a 4 column layout and then changing to 8 columns and then 12 columns.
I do it like this:
$total-columns: 4;
$column-width: 4em;
$gutter-width: 1em;
$grid-padding: $gutter-width;
$show-grid-backgrounds: true;
#include border-box-sizing;
// breakpoint variables
$M: 30em;
$L: 50em;
and the scss:
.page {
#include container;
#include susy-grid-background;
// Now create a media-query breakpoint at the min-width of 30em and use a larger grid and modify the layout
#include at-breakpoint($M 8) {
// This will create a new container with a total of 8 columns
#include container;
#include susy-grid-background;
// Now modify the inner elements to their new home
nav { #include span-columns(2,8); }
.main { #include span-columns(6 omega,8); }
}
#include at-breakpoint($L 12) {
// This will create a new container with a total of 12 columns
#include container;
#include susy-grid-background;
// Now modify the inner elements to their new home
nav { #include span-columns(2,12); }
.main {
#include span-columns(10 omega,12);
.content {
#include span-columns(8,10);
}
.summary {
#include span-columns(2 omega,10);
}
}
}
footer {clear: both;}
}
This also works ok, but I can't make all the layouts liquid as in the first example. For example, at 450px wide the 4 column layout doesn't fill the viewport. The same happens at 768px, the 8 columns don't fill the viewport. I'd like the layout to always fill the available width, as in the first example, as well as change columns according to defined breakpoints.
Is that the normal Susy behaviour or is it possible to do it in another way?
Excuse me if this is a newbie question, but I'm just at the beginning and I'd like to make things clear before using Susy on real projects.
Thanks.
Here is how I handle responsive grids, maybe it will help you.
I have a few variables I define for each breakpoint (which I like to name by the number of columns) for instance:
// 6 Columns -------------------------------------------------------------------
$six-gut-width : .5rem;
$six-padding : 0;
$six-width : 6 * $column-width + 5 * $six-gut-width + $six-padding * 2;
// 8 Columns -------------------------------------------------------------------
$eight-width : 8 * $column-width + 7 * $gutter-width + $grid-padding * 2;
This way I have both the actual width and number of columns to use in my at-breakpoint calls.
Then my breakpoints break down like this:
#include at-breakpoint($six-width 6 $eight-width) {
// Breakpoint specific scss
.page { set-container-width(6); }
}
I like to keep the breakpoint specific stuff in it's own partial in a breakpoints directory (but you don't have to) i.e: breakpoints/_6-cols.scss, breakpoints/_8-cols.scss etc.
If you want to cascade to a larger breakpoint then leave off the third parameter on at-breakpoint(), or set it to something higher than the next level. Also be sure you're setting set-container-width instead of container in your breakpoint declarations. Check out set-container-width on Susy docs
Hope this helps you. Best of luck.

How to access many images from folder

I am trying to process many picture's at a time and then make all to equal size
Mat pic = imread ("C:\\Pick");
for (int i=0;i<10;i++)
{
imshow("mainwin" , pick);
resize (pick,re_pic,size(150,100));
}
Pick is a folder which contain 10 different picture's
You can get list of images in directory and then process them.
#include <vector>
#include <stdio.h>
#include <windows.h>
#include <iostream>
#include <string>
using namespace std;
//----------------------------------------------------------------------
// Get list of files
// Usage:
// string ImagesDir=tmp+"C:\\Images\\*.jpg";
// vector<string> files=listFilesInDirectory(ImagesDir);
//----------------------------------------------------------------------
vector<string> listFilesInDirectory(string directoryName)
{
WIN32_FIND_DATA FindFileData;
HANDLE hFind = FindFirstFile(directoryName.c_str(), &FindFileData);
vector<string> listFileNames;
listFileNames.push_back(FindFileData.cFileName);
while (FindNextFile(hFind, &FindFileData))
listFileNames.push_back(FindFileData.cFileName);
return listFileNames;
}
...
// somewhere in main
string YourImagesDirectory="C:\\Pick\\";
vector<string> files=listFilesInDirectory(YourImagesDirectory+"*.jpg");
for(int i=0;i<files.size();i++)
{
Mat img=imread(YourImagesDirectory+files[i]);
imshow("mainwin" , img);
...
}
...

Resources