45void Viewer::createMenus()
47 fileMenu =
new QMenu(
tr(
"&File"),
this);
48 brightnessMenu =
new QMenu(
tr(
"&Brightness"),
this);
69 menuMap[noBrightness] =
None;
70 menuMap[quarterBrightness] =
Quarter;
71 menuMap[halfBrightness] =
Half;
73 menuMap[fullBrightness] =
Full;
75 currentBrightness = fullBrightness;
96QFrame* Viewer::createCentralWidget()
104 QSize labelSize(256, 256);
136 tr(
"Choose an image file to open"),
path,
tr(
"Images (*.*)"));
139 openImageFile(imageFile);
161 brightness = 0;
break;
163 brightness = 64;
break;
165 brightness = 128;
break;
167 brightness = 191;
break;
169 brightness = 255;
break;
174 currentBrightness = action;
188void Viewer::openImageFile(
QString &imageFile)
192 if (originalImage.
load(imageFile)) {
202 magentaWidget->
setImage(scaledImage);
203 yellowWidget->
setImage(scaledImage);
208 tr(
"The selected file could not be opened."),
229 int darkness = 255 - brightness;
231 for (
int y = 0;
y < newImage.
height(); ++
y) {
232 for (
int x = 0;
x < newImage.
width(); ++
x) {
238 float cyan1 = 255 -
qRed(
p1);
240 float yellow1 = 255 -
qBlue(
p1);
243 float cyan2 = 255 -
qRed(
p2);
245 float yellow2 = 255 -
qBlue(
p2);
248 float cyan3 = 255 -
qRed(p3);
249 float magenta3 = 255 -
qGreen(p3);
250 float yellow3 = 255 -
qBlue(p3);
253 qMax(255 -
int(cyan1+cyan2+cyan3) - darkness, 0),
254 qMax(255 -
int(magenta1+magenta2+magenta3) - darkness, 0),
255 qMax(255 -
int(yellow1+yellow2+yellow3) - darkness, 0));
271 tr(
"Choose a filename to save the image"),
"",
tr(
"Images (*.png)"));
279 if (!finalWidget->
pixmap().
save(newImageFile,
"PNG"))
281 tr(
"The file could not be saved."),
287 tr(
"Please enter a valid filename."),
The QAction class provides an abstraction for user commands that can be added to different user inter...
void triggered(bool checked=false)
This signal is emitted when an action is activated by the user; for example, when the user clicks a m...
The QColor class provides colors based on RGB, HSV or CMYK values.
QRgb rgb() const noexcept
Returns the RGB value of the color.
static void quit()
\threadsafe
static QString getSaveFileName(QWidget *parent=nullptr, const QString &caption=QString(), const QString &dir=QString(), const QString &filter=QString(), QString *selectedFilter=nullptr, Options options=Options())
This is a convenience static function that will return a file name selected by the user.
static QString getOpenFileName(QWidget *parent=nullptr, const QString &caption=QString(), const QString &dir=QString(), const QString &filter=QString(), QString *selectedFilter=nullptr, Options options=Options())
This is a convenience static function that returns an existing file selected by the user.
\inmodule QtCore \reentrant
QString baseName() const
Returns the base name of the file without the path.
QString absoluteFilePath() const
Returns an absolute path including the file name.
QDir absoluteDir() const
Returns the file's absolute path as a QDir object.
The QFrame class is the base class of widgets that can have a frame.
The QGridLayout class lays out widgets in a grid.
void addWidget(QWidget *w)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void setSpacing(int spacing) override
This function sets both the vertical and horizontal spacing to spacing.
QImage scaled(int w, int h, Qt::AspectRatioMode aspectMode=Qt::IgnoreAspectRatio, Qt::TransformationMode mode=Qt::FastTransformation) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
void setPixel(int x, int y, uint index_or_rgb)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QRgb pixel(int x, int y) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
QImage copy(const QRect &rect=QRect()) const
Returns a sub-area of the image as a new image.
int width() const
Returns the width of the image.
bool isNull() const
Returns true if it is a null image, otherwise returns false.
int height() const
Returns the height of the image.
bool load(QIODevice *device, const char *format)
This is an overloaded member function, provided for convenience. It differs from the above function o...
The QKeySequence class encapsulates a key sequence as used by shortcuts.
void setSizeConstraint(SizeConstraint)
void setCentralWidget(QWidget *widget)
Sets the given widget to be the main window's central widget.
bool contains(const Key &key) const
static StandardButton warning(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
static QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
Converts the given image to a pixmap using the specified flags to control the conversion.
bool save(const QString &fileName, const char *format=nullptr, int quality=-1) const
Saves the pixmap to the file with the given fileName using the specified image file format and qualit...
\macro QT_RESTRICTED_CAST_FROM_ASCII
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
void setBrightness(QAction *action)
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
constexpr const T & qMax(const T &a, const T &b)
GLint GLint GLint GLint GLint x
[0]
GLsizei const GLchar *const * path
QT_BEGIN_NAMESPACE typedef unsigned int QRgb
constexpr int qRed(QRgb rgb)
constexpr int qGreen(QRgb rgb)
constexpr int qBlue(QRgb rgb)
QFileInfo info(fileName)
[8]