diff --git a/CMakeLists.txt b/CMakeLists.txt index 1f303dbbe..12495dba4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,6 +44,7 @@ set(okularcore_SRCS core/page.cpp core/pagetransition.cpp core/textpage.cpp + core/utils.cpp ) kde4_add_ui_files(okularcore_SRCS diff --git a/core/utils.cpp b/core/utils.cpp new file mode 100644 index 000000000..cb957f856 --- /dev/null +++ b/core/utils.cpp @@ -0,0 +1,42 @@ +/*************************************************************************** + * Copyright (C) 2006 by Luigi Toscano * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ + +#include "utils.h" + +namespace okularUtils +{ + +QRect rotateRect( QRect source, int width, int height, int orientation ) +{ + QRect ret; + + // adapt the coordinates of the boxes to the rotation + switch ( orientation ) + { + case 1: + ret = QRect( width - source.y() - source.height(), source.x(), + source.height(), source.width() ); + break; + case 2: + ret = QRect( width - source.x() - source.width(), height - source.y() - source.height(), + source.width(), source.height() ); + break; + case 3: + ret = QRect( source.y(), height - source.x() - source.width(), + source.height(), source.width() ); + break; + case 0: // no modifications + default: // other cases + ret = source; + } + + return ret; +} + +} diff --git a/core/utils.h b/core/utils.h new file mode 100644 index 000000000..dc020286d --- /dev/null +++ b/core/utils.h @@ -0,0 +1,30 @@ +/*************************************************************************** + * Copyright (C) 2006 by Luigi Toscano * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ + +#ifndef _OKULAR_UTILS_H_ +#define _OKULAR_UTILS_H_ + +#include "okular_export.h" + +#include + +/** + * Namespace with utility functions + */ +namespace okularUtils +{ + /** + * Rotate the rect \p source in the area \p width x \p height with the + * specified \p orientation . + */ + QRect OKULAR_EXPORT rotateRect( QRect source, int width, int height, int orientation ); +}; + + +#endif